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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Grocy.Components.ProductPicker.IsRequired = function() {
|
||||||
|
return this.GetPicker().prop("required");
|
||||||
|
}
|
||||||
|
|
||||||
Grocy.Components.ProductPicker.Require = function() {
|
Grocy.Components.ProductPicker.Require = function() {
|
||||||
this.GetPicker().prop("required", true);
|
this.GetPicker().prop("required", true);
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -147,7 +151,10 @@ Grocy.Components.ProductPicker.IsOpen = function() {
|
||||||
// initialize Select2 product picker
|
// initialize Select2 product picker
|
||||||
var lastProductSearchTerm = '';
|
var lastProductSearchTerm = '';
|
||||||
Grocy.Components.ProductPicker.GetPicker().select2({
|
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: {
|
ajax: {
|
||||||
delay: 150,
|
delay: 150,
|
||||||
transport: function(params, success, failure) {
|
transport: function(params, success, failure) {
|
||||||
|
|
@ -189,7 +196,10 @@ Grocy.Components.ProductPicker.GetPicker().select2({
|
||||||
var handleEmptyResponse = function() {
|
var handleEmptyResponse = function() {
|
||||||
if (responded || complete < xhrs.length) return;
|
if (responded || complete < xhrs.length) return;
|
||||||
success({
|
success({
|
||||||
results: [],
|
results: Grocy.Components.ProductPicker.IsRequired() ? [] : [{
|
||||||
|
id: 'all',
|
||||||
|
text: __t('All'),
|
||||||
|
}],
|
||||||
pagination: {
|
pagination: {
|
||||||
more: false
|
more: false
|
||||||
}
|
}
|
||||||
|
|
@ -221,12 +231,15 @@ Grocy.Components.ProductPicker.GetPicker().select2({
|
||||||
Grocy.Components.ProductPicker.SetState('barcode', term);
|
Grocy.Components.ProductPicker.SetState('barcode', term);
|
||||||
|
|
||||||
success({
|
success({
|
||||||
results: results.map(function(result) {
|
results: (Grocy.Components.ProductPicker.IsRequired() ? [] : [{
|
||||||
|
id: 'all',
|
||||||
|
text: __t('All'),
|
||||||
|
}]).concat(results.map(function(result) {
|
||||||
return {
|
return {
|
||||||
id: result.id,
|
id: result.id,
|
||||||
text: result.name
|
text: result.name
|
||||||
};
|
};
|
||||||
}),
|
})),
|
||||||
pagination: {
|
pagination: {
|
||||||
more: page * results_per_page < meta.recordsFiltered
|
more: page * results_per_page < meta.recordsFiltered
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ stockEntriesTable.columns.adjust().draw();
|
||||||
$.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
|
$.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
|
||||||
var productId = Grocy.Components.ProductPicker.GetValue();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user