mirror of
https://github.com/grocy/grocy.git
synced 2026-04-04 11:56:16 +02:00
Fix product picker default value when not required
This commit is contained in:
parent
94b6bf8eef
commit
aaeb81c087
|
|
@ -91,6 +91,10 @@ Grocy.Components.ProductPicker.Enable = function() {
|
|||
return this;
|
||||
}
|
||||
|
||||
Grocy.Components.ProductPicker.IsRequired = function() {
|
||||
return this.GetPicker().prop("required");
|
||||
}
|
||||
|
||||
Grocy.Components.ProductPicker.Require = function() {
|
||||
this.GetPicker().prop("required", true);
|
||||
return this;
|
||||
|
|
@ -147,7 +151,10 @@ Grocy.Components.ProductPicker.IsOpen = function() {
|
|||
// initialize Select2 product picker
|
||||
var lastProductSearchTerm = '';
|
||||
Grocy.Components.ProductPicker.GetPicker().select2({
|
||||
selectOnClose: true,
|
||||
placeholder: Grocy.Components.ProductPicker.IsRequired() ? null : __t('All'),
|
||||
placeholderOption: 'all',
|
||||
selectOnClose: Grocy.Components.ProductPicker.IsRequired(),
|
||||
allowClear: !Grocy.Components.ProductPicker.IsRequired(),
|
||||
ajax: {
|
||||
delay: 150,
|
||||
transport: function(params, success, failure) {
|
||||
|
|
@ -189,7 +196,10 @@ Grocy.Components.ProductPicker.GetPicker().select2({
|
|||
var handleEmptyResponse = function() {
|
||||
if (responded || complete < xhrs.length) return;
|
||||
success({
|
||||
results: [],
|
||||
results: Grocy.Components.ProductPicker.IsRequired() ? [] : [{
|
||||
id: 'all',
|
||||
text: __t('All'),
|
||||
}],
|
||||
pagination: {
|
||||
more: false
|
||||
}
|
||||
|
|
@ -221,12 +231,15 @@ Grocy.Components.ProductPicker.GetPicker().select2({
|
|||
Grocy.Components.ProductPicker.SetState('barcode', term);
|
||||
|
||||
success({
|
||||
results: results.map(function(result) {
|
||||
results: (Grocy.Components.ProductPicker.IsRequired() ? [] : [{
|
||||
id: 'all',
|
||||
text: __t('All'),
|
||||
}]).concat(results.map(function(result) {
|
||||
return {
|
||||
id: result.id,
|
||||
text: result.name
|
||||
};
|
||||
}),
|
||||
})),
|
||||
pagination: {
|
||||
more: page * results_per_page < meta.recordsFiltered
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ stockEntriesTable.columns.adjust().draw();
|
|||
$.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
|
||||
var productId = Grocy.Components.ProductPicker.GetValue();
|
||||
|
||||
if ((isNaN(productId) || productId == "" || productId == data[1])) {
|
||||
if ((isNaN(productId) || productId == "" || productId == data[1] || productId === null || productId === 'all')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user