changed focus when there is no error in the page to the first element in a form rather than no focus.

This commit is contained in:
jamiesensei
2006-10-30 06:27:15 +00:00
parent 0d6f531d8f
commit 5c52df6797
+4 -3
View File
@@ -45,18 +45,19 @@ class moodleform {
* To autofocus on first form element with error.
*
* @return string javascript to select form element with first error or
* '' if no errors.
* first element if no errors.
*/
function focus(){
$form=$this->_form;
$elkeys=array_keys($form->_elementIndex);
if (isset($form->_errors) && 0!=count($form->_errors)){
$errorkeys=array_keys($form->_errors);
$elkeys=array_keys($form->_elementIndex);
$keyinorder=array_intersect($elkeys, $errorkeys);
$el='getElementById(\'id_'.array_shift($keyinorder).'\')';
return $el;
} else{
return '';
$el='getElementById(\'id_'.array_shift($elkeys).'\')';
return $el;
}
}