diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 3cc767c1592..5e9ca5582b5 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -63,10 +63,13 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt var autoselect = '.$autoselect.'; var options = '.json_encode($ajaxoptions).'; - /* Remove product id before select another product use keyup instead of change to avoid loosing the product id. This is needed only for select of predefined product */ - /* TODO Check if we can remove this */ - $("input#search_'.$htmlname.'").keydown(function() { - $("#'.$htmlname.'").val(""); + /* Remove selected id as soon as we type or delete a char (it means old selection is wrong). Use keyup/down instead of change to avoid loosing the product id. This is needed only for select of predefined product */ + $("input#search_'.$htmlname.'").keydown(function(e) { + if (e.keyCode != 9) /* If not "Tab" key */ + { + console.log("Clear id previously selected for field '.$htmlname.'"); + $("#'.$htmlname.'").val(""); + } }); /* I disable this. A call to trigger is already done later into the select action of the autocomplete code diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index c43ecf9d038..151a9abd057 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6378,7 +6378,7 @@ function dolExplodeIntoArray($string, $delimiter = ';', $kv = '=') /** - * Set focus onto field with selector + * Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag) * * @param string $selector Selector ('#id' or 'input[name="ref"]') to use to find the HTML input field that must get the autofocus. You must use a CSS selector, so unique id preceding with the '#' char. * @return string HTML code to set focus