From 5c52df6797f3f79ef140abd2cb9389e2f250e0b0 Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Mon, 30 Oct 2006 06:27:15 +0000 Subject: [PATCH] changed focus when there is no error in the page to the first element in a form rather than no focus. --- lib/formslib.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/formslib.php b/lib/formslib.php index badc2c688e..af2ebda810 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -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; } } -- 2.39.5