]> git.mjollnir.org Git - moodle.git/commitdiff
Merged autofocus fixes for formslib to dev from stable
authormoodler <moodler>
Fri, 16 Mar 2007 01:46:17 +0000 (01:46 +0000)
committermoodler <moodler>
Fri, 16 Mar 2007 01:46:17 +0000 (01:46 +0000)
lib/formslib.php
mod/forum/post.php

index 53d8d3f110eac0b51ca5288f563adce75e27e4e2..03d3260ad80e2011be4ec2cefa33d4c2b75e9b5f 100644 (file)
@@ -129,11 +129,13 @@ class moodleform {
     /**
      * To autofocus on first form element or first element with error.
      *
+     * @param string $name if this is set then the focus is forced to a field with this name
+     *
      * @return string  javascript to select form element with first error or
      *                  first element if no errors. Use this as a parameter
      *                  when calling print_header
      */
-    function focus(){
+    function focus($name=NULL){
         $form =& $this->_form;
         $elkeys=array_keys($form->_elementIndex);
         if (isset($form->_errors) &&  0 != count($form->_errors)){
@@ -142,10 +144,12 @@ class moodleform {
         }
         $names=null;
         while (!$names){
-          $el = array_shift($elkeys);
-          $names = $form->_getElNamesRecursive($el);
+            $el = array_shift($elkeys);
+            $names = $form->_getElNamesRecursive($el);
+        }
+        if (empty($name)) {
+            $name=array_shift($names);
         }
-        $name=array_shift($names);
         $focus='forms[\''.$this->_form->getAttribute('id').'\'].elements[\''.$name.'\']';
         return $focus;
      }
index 845057dd7ca85b672dbc3cbf1b8441a8247a2ceb..a17f6f17b85906599edaf3b6b401cb20690cfc2b 100644 (file)
         // Show the discussion name in the breadcrumbs.
         $strdiscussionname = format_string($discussion->name).':';
     }
+
+    $forcefocus = empty($reply) ? NULL : 'message';
+
     if ($course->id != SITEID) {
         print_header("$course->shortname: $strdiscussionname ".
                       format_string($toppost->subject), $course->fullname,
                      "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
-                      $navmiddle $navtail", $mform_post->focus(), "", true, "", navmenu($course, $cm));
+                      $navmiddle $navtail", $mform_post->focus($forcefocus), "", true, "", navmenu($course, $cm));
 
     } else {
         print_header("$course->shortname: $strdiscussionname ".
                       format_string($toppost->subject), $course->fullname,
-                     "$navmiddle $navtail", $mform_post->focus(), "", true, "", navmenu($course, $cm));
+                     "$navmiddle $navtail", $mform_post->focus($forcefocus), "", true, "", navmenu($course, $cm));
 
     }