From 5af53b13622ca77bc851cccaa087d7e2aedc3401 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Thu, 27 Mar 2008 13:53:50 +0000 Subject: [PATCH] Automatic first field focus on page start, preserved focus sequence between form updates --- includes/page/footer.inc | 1 - includes/ui/ui_controls.inc | 2 +- includes/ui/ui_input.inc | 8 +++++- includes/ui/ui_lists.inc | 39 +++++++++++++++++++++++++++ includes/ui/ui_view.inc | 33 +++++++++++++++++------ js/inserts.js | 30 ++++++++++++--------- sales/credit_note_entry.php | 6 +++++ sales/includes/ui/sales_credit_ui.inc | 3 ++- sales/includes/ui/sales_order_ui.inc | 3 ++- sales/sales_order_entry.php | 6 +++++ 10 files changed, 105 insertions(+), 26 deletions(-) diff --git a/includes/page/footer.inc b/includes/page/footer.inc index cefc3c1a..8f3db720 100644 --- a/includes/page/footer.inc +++ b/includes/page/footer.inc @@ -9,7 +9,6 @@ function page_footer($no_menu=false, $is_index=false) if (isset($_GET['ajax'])) return; - echo set_js_focus(); // set focus on input (if $focus_on exists) if (function_exists('hyperlink_back')) hyperlink_back(); if ($no_menu == false) diff --git a/includes/ui/ui_controls.inc b/includes/ui/ui_controls.inc index 12dc0d10..7d731525 100644 --- a/includes/ui/ui_controls.inc +++ b/includes/ui/ui_controls.inc @@ -20,7 +20,6 @@ function start_form($multi=false, $sid=false, $action="", $name="") else echo "
\n"; - echo ""; } //--------------------------------------------------------------------------------- @@ -29,6 +28,7 @@ function end_form($breaks=0) { if ($breaks) br($breaks); + echo "\n"; echo "
\n"; } diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc index 67abbbde..6c09d097 100644 --- a/includes/ui/ui_input.inc +++ b/includes/ui/ui_input.inc @@ -38,7 +38,7 @@ function hidden($name, $value) function submit($name, $value, $echo=true) { - + default_focus($name); $submit_str = "\n"; if ($echo) echo $submit_str; @@ -119,6 +119,7 @@ function submit_row($name, $value, $right=true, $extra="") function button($name, $value, $onclick) { + default_focus($name); echo "\n"; } @@ -140,6 +141,7 @@ function check_value($name) function check($label, $name, $value, $submit_on_change=false) { + default_focus($name); if ($label) echo $label . " "; @@ -226,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 ""; @@ -242,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) @@ -454,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 "$label\n"; if ($value == null) @@ -472,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 "$label\n"; echo ""; diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index f271bb65..ba5f42a4 100644 --- a/includes/ui/ui_lists.inc +++ b/includes/ui/ui_lists.inc @@ -15,6 +15,7 @@ function supplier_list($name, $selected_id, $all_option=false, $submit_on_change { global $all_items; + default_focus($name); if ($selected_id == null) $selected_id = ((!isset($_POST[$name]) || $_POST[$name] == "") ? "" : $_POST[$name]); $no_supplier_list = get_company_pref('no_supplier_list'); @@ -129,6 +130,7 @@ function customer_list($name, $selected_id, $all_option=false, $submit_on_change { global $all_items; + default_focus($name); if ($selected_id == null) $selected_id = ((!isset($_POST[$name]) || $_POST[$name] == "") ? "" : $_POST[$name]); $no_customer_list = get_company_pref('no_customer_list'); @@ -245,6 +247,7 @@ function customer_branches_list($customer_id, $name, $selected_id, { global $all_items; + default_focus($name); if ($submit_on_change==true) echo ""; else @@ -387,6 +391,7 @@ function locations_list_row($label, $name, $selected_id, $all_option=false, $sub function currencies_list($name, &$selected_id, $submit_on_change=false) { + default_focus($name); if ($submit_on_change==true) echo ""; else @@ -509,6 +515,7 @@ function simple_codeandname_list($sql, $name, &$selected_id, { global $all_items; + default_focus($name); if ($submit_on_change == true) echo ""; else @@ -801,6 +811,7 @@ function base_stock_items_list($sql, $name, &$selected_id, { global $all_items; + default_focus($name); if ($submit_on_change==true) echo ""; $sql = "SELECT id, name FROM ".TB_PREF."workcentres"; @@ -1413,6 +1429,7 @@ function workcenter_list($name, $selected_id, $all_option=false) function workcenter_list_cells($label, $name, $selected_id, $all_option=false) { + default_focus($name); if ($label != null) echo "$label\n"; echo ""; @@ -1431,6 +1448,7 @@ function workcenter_list_row($label, $name, $selected_id, $all_option=false) function bank_accounts_list($name, $selected_id, $submit_on_change=false) { + default_focus($name); if ($submit_on_change==true) echo ""; else @@ -1595,6 +1614,7 @@ function gl_account_types_list_row($label, $name, $selected_id, $all_option=fals function gl_all_accounts_list($name, $selected_id, $skip_bank_accounts=false, $show_group=false, $onchange="") { + default_focus($name); echo ""; if ($selected_id == null) @@ -1756,6 +1778,7 @@ function bank_account_types_list($name, &$selected_id) { $bank_account_types = bank_account_types::get_all(); + default_focus($name); echo ""; if ($selected_id == null) @@ -1861,6 +1886,7 @@ function dateformats_list_row($label, $name, $value) { global $dateformats; + default_focus($name); echo "$label\n"; echo ""; @@ -1913,6 +1940,7 @@ function thoseps_list_row($label, $name, $value) { global $thoseps; + default_focus($name); echo "$label\n"; echo ""; @@ -1965,6 +1994,7 @@ function themes_list_row($label, $name, $value) { global $path_to_root; + default_focus($name); $path = $path_to_root.'/themes/'; $themes = array(); $themedir = opendir($path); @@ -1998,6 +2028,7 @@ function pagesizes_list_row($label, $name, $value) { global $pagesizes; + default_focus($name); echo "$label\n"; echo ""; @@ -2048,6 +2080,7 @@ function systypes_list_cells($label, $name, $value, $submit_on_change=false) { global $systypes_array; + default_focus($name); if ($label != null) echo "$label\n"; echo ""; @@ -2113,6 +2149,7 @@ function supp_allocations_list_cells($name, $selected) function policy_list_cells($label, $name, $selected) { + default_focus($name); if ($selected == null) { $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]); @@ -2136,6 +2173,7 @@ function policy_list_row($label, $name, $selected) function credit_type_list_cells($label, $name, $selected, $submit_on_change=false) { + default_focus($name); if ($selected == null) { $selected = (!isset($_POST[$name]) ? "Return" : $_POST[$name]); @@ -2163,6 +2201,7 @@ function credit_type_list_row($label, $name, $selected, $submit_on_change=false) function number_list($name, $selected, $from, $to, $firstlabel="") { + default_focus($name); if ($selected == null) { $selected = (!isset($_POST[$name]) ? $from : $_POST[$name]); diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index 3a47f128..d76dd824 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -553,29 +553,46 @@ function get_js_open_window($width, $height) return $js; } -$focus_on = array(); +//$focus_on = array(); /* Setting focus on element $name in $form. If $form<0 $name is element id. */ function set_focus($name, $form_no=0) { - global $focus_on; - $focus_on['name'] = $name; - $focus_on['form'] = $form_no; +// global $focus_on; +// $focus_on['name'] = $name; +// $focus_on['form'] = $form_no; + $_POST['_focus'] = $name; } - +// +// Set default focus on first field $name if not set yet +// +function default_focus($name, $form_no=0) { +// global $focus_on; +// if (!isset($focus_on['name']) && (!isset($_POST['_focus']) || $_POST['_focus']=='') ) { +//echo "

$name

"; +// $focus_on['name'] = $name; +// $focus_on['form'] = $form_no; +// } + if (!isset($_POST['_focus'])) { + $_POST['_focus'] = $name; + } +} +/* function set_js_focus() { global $focus_on; $js = ''; - if (isset($focus_on['name'])) { + +// if (isset($focus_on['name'])) { + $js = ""; - } +// } return $js; } - +*/ function get_js_png_fix() { $js = "