From: nicolasconnault Date: Mon, 12 Mar 2007 06:43:24 +0000 (+0000) Subject: MDL-8737 - Added a focus() to the generated validation JS, so that if an element... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=2ef7c374a4f6833dd10ff5c24d8817010426407e;p=moodle.git MDL-8737 - Added a focus() to the generated validation JS, so that if 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. --- diff --git a/lib/formslib.php b/lib/formslib.php index 085cb51d4c..53d8d3f110 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -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); @@ -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; }