Skip to content

Commit

Permalink
MDL-12199 problem with "Show advanced" used after pressing of enter i…
Browse files Browse the repository at this point in the history
…n forms; merged from MOODLE_19_STABLE
  • Loading branch information
skodak committed Nov 17, 2007
1 parent 6ba472c commit 7c9b1d3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/formslib.php
Expand Up @@ -1724,14 +1724,23 @@ function renderHeader(&$header) {
}

if (isset($this->_advancedElements[$name])){
// 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
$showtext="'".get_string('showadvanced', 'form')."'";
$hidetext="'".get_string('hideadvanced', 'form')."'";
//onclick returns false so if js is on then page is not submitted.
$onclick = 'return showAdvancedOnClick(this, '.$hidetext.', '.$showtext.');';
$button = '<input name="'.$elementName.'" value="'.$buttonlabel.'" type="submit" onclick="'.$onclick.'" />';
$header_html =str_replace('{button}', $button, $header_html);
$button_js = '<input name="'.$elementName.'" value="'.$buttonlabel.'" type="button" onclick="'.$onclick.'" />';
$button_nojs = '<input name="'.$elementName.'" value="'.$buttonlabel.'" type="submit" />';
$button = '<script type="text/javascript">
//<![CDATA[
document.write("'.addslashes_js($button_js).'")
//]]>
</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);
} else {
$header_html =str_replace('{button}', '', $header_html);
$header_html = str_replace('{button}', '', $header_html);
}

if ($this->_fieldsetsOpen > 0) {
Expand Down

0 comments on commit 7c9b1d3

Please sign in to comment.