Automatic first field focus on page start, preserved focus sequence
[fa-stable.git] / includes / ui / ui_input.inc
index 0831e6103df0fd66369deac64cc2bbc30bfc66d1..6c09d0979f83f6fcf806ed45628396a49152249a 100644 (file)
@@ -1,5 +1,25 @@
 <?php
 
+//------------------------------------------------------------------------------
+//    Seek for _POST variable with $prefix.
+//    If var is found returns variable name with prefix stripped,
+//    and null or -1 otherwise.
+//
+function find_submit($prefix, $numeric=true) {
+
+    foreach($_POST as $postkey=>$postval ) {
+       if (strpos($postkey, $prefix) === 0) {
+               $id = substr($postkey, strlen($prefix));
+               return $numeric ? (int)$id : $id;
+       }
+    }
+    return $numeric ? -1 : null;
+}
+
+//------------------------------------------------------------------------------
+//
+//     Read numeric value from user formatted input
+//
 function input_num($postname=null) {
        if (!isset($_POST[$postname])) 
          return null;
@@ -18,6 +38,7 @@ function hidden($name, $value)
 
 function submit($name, $value, $echo=true)
 {
+       default_focus($name);
        $submit_str = "<input type=\"submit\" class=\"inputsubmit\" name=\"$name\" value=\"$value\">\n";
        if ($echo)
                echo $submit_str;
@@ -98,7 +119,8 @@ function submit_row($name, $value, $right=true, $extra="")
 
 function button($name, $value, $onclick)
 {
-       echo "<input type=\"button\" class=\"inputsubmit\" name=\"$name\" value=\"$value\" onclick=\"$onclick\" />\n";
+  default_focus($name);
+  echo "<input type=\"button\" class=\"inputsubmit\" name=\"$name\" value=\"$value\" onclick=\"$onclick\" />\n";
 }
 
 function button_cell($name, $value, $onclick)
@@ -119,6 +141,7 @@ function check_value($name)
 
 function check($label, $name, $value, $submit_on_change=false)
 {
+       default_focus($name);
        if ($label)
                echo $label . "  ";
 
@@ -205,6 +228,7 @@ function label_row($label, $value, $params="", $params2="", $leftfill=0)
 
 function text_cells($label, $name, $value, $size="", $max="", $params="", $post_label="", $disabled="")
 {
+       default_focus($name);
        if ($label != null)
                label_cell($label, $params);
        echo "<td>";
@@ -221,6 +245,7 @@ function text_cells($label, $name, $value, $size="", $max="", $params="", $post_
 
 function text_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null)
 {
+       default_focus($name);
        if (!isset($_POST[$name]) || $_POST[$name] == "")
        {
                if ($init)
@@ -291,7 +316,7 @@ function date_cells($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_
                        $_POST[$name] = $init;
        }
        if ($use_date_picker)
-               $post_label = "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
+               $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.forms[0].$name);\">"
                . "     <img src='$path_to_root/themes/default/images/cal.gif' width='16' height='16' border='0' alt='"._('Click Here to Pick up the date')."'></a>\n";
        else
                $post_label = "";
@@ -433,6 +458,7 @@ function small_qty_cells($label, $name, $init=null, $params=null, $post_label=nu
 
 function textarea_cells($label, $name, $value, $cols, $rows, $params="")
 {
+       default_focus($name);
        if ($label != null)
                echo "<td $params>$label</td>\n";
        if ($value == null)
@@ -451,6 +477,7 @@ function textarea_row($label, $name, $value, $cols, $rows, $params="")
 
 function text_row_with_submit($label, $name, $value, $size, $max, $input_name, $input_value)
 {
+       default_focus($name);
        echo "<tr><td>$label</td>\n";
        echo "<td>";