From 8fc8d5990ec8f866b0f86c36633dcab9e0a7ecdf Mon Sep 17 00:00:00 2001 From: Leo Stoyanov Date: Tue, 7 Jan 2025 23:31:37 +0000 Subject: [PATCH] Bug 38839: Add validation for replacement price in item and batch modification forms Adds validation for the replacement price on the item input and batch modification forms. Test plan: 1. Search for a record in the staff interface, select any record with an item, click "Edit", and select "Manage items". 2. Click "Actions" on the item in the table, select "Edit", and input an invalid "v - Cost, replacement price" (e.g., 1,00). 3. Click "Save changes" and the form will submit but with no price shown in the table on the next page. 4. Apply the patch, update the CSS (yarn build) and restart everything (restart_all). 5. Repeat steps 1-3. A red error message will now appear below the input field, notifying the user that only numbers and periods are allowed. The user will not be able to submit the form. 6. The same change was also made to the batch modification form under Cataloging > Batch item modification. Signed-off-by: David Nind --- .../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