formslib MDL-19626 Fixed broken show/hide advanced button

Updated formslib showadvanced inline JS to use new $PAGE methods
and replaced inline noscript with css handled display
This commit is contained in:
samhemelryk 2009-06-29 01:58:11 +00:00
parent a36a2bc8e5
commit 9262d2d30f
2 changed files with 17 additions and 6 deletions

View File

@ -2113,6 +2113,15 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
*/
function renderHeader(&$header) {
global $PAGE;
static $advformcount;
// This ensures that if 2(+) advanced buttons are used
// that all show/hide buttons appear in the correct place
// Because of now using $PAGE->requires->js_function_call
if ($advformcount==null) {
$advformcount = 1;
}
$name = $header->getName();
$id = empty($name) ? '' : ' id="' . $name . '"';
@ -2141,16 +2150,15 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
$PAGE->requires->yui_lib('event');
// this is tricky - the first submit button on form is "clicked" if user presses enter
// we do not want to "submit" using advanced button if javascript active
$button_nojs = '<input name="'.$elementName.'" value="'.$buttonlabel.'" type="submit" />';
$button_nojs = '<input name="'.$elementName.'" id="'.$elementName.(string)$advformcount.'" class="showadvancedbtn" value="'.$buttonlabel.'" type="submit" />';
$buttonlabel = addslashes_js($buttonlabel);
$showtext = addslashes_js(get_string('showadvanced', 'form'));
$hidetext = addslashes_js(get_string('hideadvanced', 'form'));
$button = '<script id="' . $name . '_script" type="text/javascript">' . "
showAdvancedInit('{$name}_script', '$elementName', '$buttonlabel', '$hidetext', '$showtext');
" . '</script><noscript><div style="display:inline">'.$button_nojs.'</div></noscript>'; // the extra div should fix xhtml validation
$header_html = str_replace('{button}', $button, $header_html);
$PAGE->requires->js_function_call('showAdvancedInit', Array($elementName.(string)$advformcount, $elementName, $buttonlabel, $hidetext, $showtext));
$advformcount++;
$header_html = str_replace('{button}', $button_nojs, $header_html);
} else {
$header_html = str_replace('{button}', '', $header_html);
}

View File

@ -630,6 +630,9 @@ div.hide {
width:100%;
text-align:right;
}
.jsenabled .advancedbutton .showadvancedbtn {
display:none;
}
.mform div.fitem {
clear: both;
width: 100%;