From 31ee2fdeb52ac3a6b243960274a4f196f581ae85 Mon Sep 17 00:00:00 2001 From: Leo Stoyanov Date: Tue, 7 Jan 2025 23:31:37 +0000 Subject: [PATCH] Bug 38839: Added validation for replacementprice in items form and batch mod form. Validation has been added for the batch mod form because it also takes replacement price as input and lacked validation. To recreate: 1. On the dashboard, make sure to select "Search catalog". 2. Search in the catalog, select anything, click "Edit", and select "Manage items". 3. Click "Actions" on the item in the table, select "Edit", and input an invalid "Cost, replacement price" (e.g., 1,00). 4. Click "Save changes" and the form will submit but with no price shown in the table on the next page. 5. Apply the patch and repeat steps 1-4. A red error message below the input will appear, notifying the user that only numbers and periods are allowed. The user will not be able to submit the form. 6. The same bug and fix should apply to the batch mod form under "Cataloging" and "Batch item modification". --- .../prog/css/src/staff-global.scss | 20 +++++++++++++++++++ .../prog/en/includes/html_helpers.inc | 4 ++++ .../en/includes/modal-replacementprice.inc | 16 +++++++++++++++ .../prog/en/modules/cataloguing/additem.tt | 1 + .../prog/js/cataloging_additem.js | 19 ++++++++++++++++++ .../intranet-tmpl/prog/js/pages/batchMod.js | 20 +++++++++++++++++++ 6 files changed, 80 insertions(+) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/modal-replacementprice.inc diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss index 878634a08a..f29e167ab0 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss +++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss @@ -4896,3 +4896,23 @@ div .suggestion_note { } } } + +#cat_additem .replacementprice_error_message { + color: red; + margin-left: 20vw; +} + +#tools_batchMod-edit .replacementprice_error_message { + color: red; + margin-left: 24.5vw; +} + +.replacementprice_error_message.hidden { + display: none; +} + +@media (max-width: 1000px) { + .replacementprice_error_message { + margin-left: 23.5vw; + } +} \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc index 50d618f392..0d5f628377 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc @@ -216,6 +216,10 @@ + + [% IF subfield.subfield == 'v' %] + + [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/modal-replacementprice.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/modal-replacementprice.inc new file mode 100644 index 0000000000..5f1c704286 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/modal-replacementprice.inc @@ -0,0 +1,16 @@ + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index a41569fe99..cec36d91e6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -7,6 +7,7 @@ [% USE TablesSettings %] [% PROCESS 'i18n.inc' %] [% INCLUDE 'doc-head-open.inc' %] +[% INCLUDE 'modal-replacementprice.inc' %] [% FILTER collapse %] [% t("Items") | html %] › [% IF ( biblio.author ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js index d4f28bbf84..3ef01ddcc5 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js @@ -4,6 +4,25 @@ var browser = KOHA.browser(searchid, parseInt(biblionumber, 10)); browser.show(); $(document).ready(function(){ + $("#cataloguing_additem_newitem form").on("submit", function (e) { + var replacementprice = $("input[name='items.replacementprice']").val(); + if (!/^[0-9.]+$/.test(replacementprice)) { + e.preventDefault(); + return false; + } + return true; + }); + + $("input[name='items.replacementprice']").on("input", function () { + var value = $(this).val(); + var isValid = /^[0-9.]*$/.test(value); + + if (!isValid) { + $('.replacementprice_error_message').removeClass('hidden'); + } else { + $('.replacementprice_error_message').addClass('hidden'); + } + }); // Remove the onclick event defined in browser.js, // otherwise the deletion confirmation will not work correctly diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/batchMod.js b/koha-tmpl/intranet-tmpl/prog/js/pages/batchMod.js index df428f831b..84e86277d9 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/batchMod.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/batchMod.js @@ -118,6 +118,26 @@ function hideAllColumns() { } $(document).ready(function () { + $('form[action="batchMod.pl"]').on("submit", function (e) { + var replacementprice = $("input[name='items.replacementprice']").val(); + if (!/^[0-9.]+$/.test(replacementprice)) { + e.preventDefault(); + return false; + } + return true; + }); + + $("input[name='items.replacementprice']").on("input", function () { + var value = $(this).val(); + var isValid = /^[0-9.]*$/.test(value); + + if (!isValid) { + $('.replacementprice_error_message').removeClass('hidden'); + } else { + $('.replacementprice_error_message').addClass('hidden'); + } + }); + var items_table = KohaTable("itemst", { "columnDefs": [ { "targets": [0, 1], "orderable": false, "searchable": true }, -- 2.39.5