diff --git a/grocy.js b/grocy.js index a5060c4a..04294c18 100644 --- a/grocy.js +++ b/grocy.js @@ -75,3 +75,8 @@ Grocy.EmptyElementWhenMatches = function(selector, text) $(selector).text(''); } }; + +String.prototype.contains = function(search) +{ + return this.toLowerCase().indexOf(search.toLowerCase()) !== -1; +}; diff --git a/views/consumption.js b/views/consumption.js index f0ea5660..1e8e89be 100644 --- a/views/consumption.js +++ b/views/consumption.js @@ -88,7 +88,28 @@ $('#product_id').on('change', function(e) $(function() { - $('.combobox').combobox({ appendId: '_text_input' }); + $('.combobox').combobox({ + appendId: '_text_input', + matcher: function(text) + { + var input = $('#product_id_text_input').val(); + var optionElement = $("#product_id option:contains('" + text + "')").first(); + var additionalSearchdata = optionElement.data('additional-searchdata'); + + if (text.contains(input)) + { + return true; + } + else if (additionalSearchdata !== null && additionalSearchdata.length > 0) + { + return additionalSearchdata.contains(input); + } + else + { + return false; + } + } + }); $('#amount').val(1); $('#product_id').val(''); diff --git a/views/consumption.php b/views/consumption.php index 77115f69..bb5bfb4b 100644 --- a/views/consumption.php +++ b/views/consumption.php @@ -7,7 +7,7 @@
diff --git a/views/productform.js b/views/productform.js index ed4ebf53..98734d04 100644 --- a/views/productform.js +++ b/views/productform.js @@ -42,7 +42,7 @@ $(function() Grocy.FetchJson('/api/get-object/products/' + Grocy.EditObjectId, function (product) { - if (product.barcode.length > 0) + if (product.barcode !== null && product.barcode.length > 0) { product.barcode.split(',').forEach(function(item) { diff --git a/views/productform.php b/views/productform.php index 7235cdcd..91183028 100644 --- a/views/productform.php +++ b/views/productform.php @@ -18,8 +18,8 @@
- - + +
diff --git a/views/purchase.js b/views/purchase.js index 9b252bf1..8c65fc96 100644 --- a/views/purchase.js +++ b/views/purchase.js @@ -90,7 +90,28 @@ $(function() }); $('.datepicker').trigger('change'); - $('.combobox').combobox({ appendId: '_text_input' }); + $('.combobox').combobox({ + appendId: '_text_input', + matcher: function(text) + { + var input = $('#product_id_text_input').val(); + var optionElement = $("#product_id option:contains('" + text + "')").first(); + var additionalSearchdata = optionElement.data('additional-searchdata'); + + if (text.contains(input)) + { + return true; + } + else if (additionalSearchdata !== null && additionalSearchdata.length > 0) + { + return additionalSearchdata.contains(input); + } + else + { + return false; + } + } + }); $('#amount').val(1); $('#best_before_date').val(''); diff --git a/views/purchase.php b/views/purchase.php index 0e7d44ef..32acde81 100644 --- a/views/purchase.php +++ b/views/purchase.php @@ -7,7 +7,7 @@