diff --git a/localization/strings.pot b/localization/strings.pot index e2f7d8c4..55139c2d 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -2074,3 +2074,6 @@ msgstr "" msgid "Print options" msgstr "" + +msgid "A product or a note is required" +msgstr "" diff --git a/public/viewjs/shoppinglistitemform.js b/public/viewjs/shoppinglistitemform.js index e6a6ea39..61ddce82 100644 --- a/public/viewjs/shoppinglistitemform.js +++ b/public/viewjs/shoppinglistitemform.js @@ -167,6 +167,9 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) } ); } + + $("#note").trigger("input"); + $("#product_id").trigger("input"); }); Grocy.FrontendHelpers.ValidateForm('shoppinglist-form'); @@ -235,4 +238,16 @@ if (GetUriParam("embedded") !== undefined) } } +var eitherRequiredFields = $("#product_id,#product_id_text_input,#note"); +eitherRequiredFields.on("input", function() +{ + eitherRequiredFields.attr("required", ""); + if (!$(this).val().isEmpty()) + { + eitherRequiredFields.not(this).removeAttr("required"); + } + + Grocy.FrontendHelpers.ValidateForm('shoppinglist-form'); +}); + Grocy.Components.UserfieldsForm.Load(); diff --git a/views/components/productpicker.blade.php b/views/components/productpicker.blade.php index d9b37b04..59d33df2 100644 --- a/views/components/productpicker.blade.php +++ b/views/components/productpicker.blade.php @@ -11,6 +11,7 @@ @php if(!isset($disabled)) { $disabled = false; } @endphp @php if(empty($hint)) { $hint = ''; } @endphp @php if(empty($nextInputSelector)) { $nextInputSelector = ''; } @endphp +@php if(empty($validationMessage)) { $validationMessage = 'You have to select a product'; } @endphp