Skip to content

Commit

Permalink
MDL-8737 - Added a focus() to the generated validation JS, so that if…
Browse files Browse the repository at this point in the history
… an element fails client-side validation, the focus jumps straight to it when the submit button is clicked. This doesn't yet work with HTMLArea elements.
  • Loading branch information
nicolasconnault committed Mar 12, 2007
1 parent eab3ae1 commit 1f32258
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/formslib.php
Expand Up @@ -1118,7 +1118,13 @@ function validate_' . $this->_formName . '_' . $elementName . '(element) {
}
';
$validateJS .= '
ret = validate_' . $this->_formName . '_' . $elementName.'(frm.elements[\''.$elementName.'\']) && ret;';
ret = validate_' . $this->_formName . '_' . $elementName.'(frm.elements[\''.$elementName.'\']) && ret;
if (!ret && !first_focus) {
first_focus = true;
frm.elements[\''.$elementName.'\'].focus();
}
';

// Fix for bug displaying errors for elements in a group
//unset($element);
//$element =& $this->getElement($elementName);
Expand All @@ -1136,9 +1142,9 @@ function validate_' . $this->_formName . '(frm) {
return true;
}
var ret = true;
var frm = document.getElementById(\''. $this->_attributes['id'] .'\')
var first_focus = false;
' . $validateJS . ';
return ret;
}
Expand Down

0 comments on commit 1f32258

Please sign in to comment.