mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 22:23:23 +00:00
Repair NaN bug for autocomplete on counter click (#583)
* Repair NaN bug for autocomplete on counter click
This commit is contained in:
parent
b12e8dc147
commit
982fc09908
@ -45,7 +45,6 @@ $(function () {
|
|||||||
const code_field = $("#code_field");
|
const code_field = $("#code_field");
|
||||||
|
|
||||||
let quantity = "";
|
let quantity = "";
|
||||||
let search = "";
|
|
||||||
code_field.autocomplete({
|
code_field.autocomplete({
|
||||||
select: function (event, ui) {
|
select: function (event, ui) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -56,10 +55,10 @@ $(function () {
|
|||||||
code_field.val(quantity + ui.item.value);
|
code_field.val(quantity + ui.item.value);
|
||||||
},
|
},
|
||||||
source: function (request, response) {
|
source: function (request, response) {
|
||||||
// by the dark magic of JS, parseInt("123abc") === 123
|
const res = /^(\d+x)?(.*)/i.exec(request.term);
|
||||||
quantity = parseInt(request.term);
|
quantity = res[1] || "";
|
||||||
search = request.term.slice(quantity.toString().length)
|
const search = res[2];
|
||||||
let matcher = new RegExp($.ui.autocomplete.escapeRegex(search), "i");
|
const matcher = new RegExp($.ui.autocomplete.escapeRegex(search), "i" );
|
||||||
response($.grep(products_autocomplete, function(value) {
|
response($.grep(products_autocomplete, function(value) {
|
||||||
value = value.tags;
|
value = value.tags;
|
||||||
return matcher.test( value );
|
return matcher.test( value );
|
||||||
|
Loading…
Reference in New Issue
Block a user