From c6c3746ffc93729a1137fcc78951e0eabf0f3667 Mon Sep 17 00:00:00 2001 From: Leo Stoyanov Date: Thu, 23 Jan 2025 22:48:20 +0000 Subject: [PATCH] Bug 38839: (follow-up) Added stricter validation for replacement price fields. Adds validation for the replacement price on the item input and batch modification forms. This follow-up utilizes a new jQuery "replacement_price_decimal" validator for more strict validation; that is, there may only be up to 6 digits before the decimal and 2 digits after the decimal. 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" (for example, 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), restart everything (restart_all), AND clear browser cache. 5. Repeat steps 1-3. A red error message will now appear to the right of 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. --- .../prog/en/includes/html_helpers.inc | 3 +-- koha-tmpl/intranet-tmpl/prog/js/staff-global.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) 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 e1c095c7777..04691d9a048 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc @@ -237,12 +237,11 @@ /> [% ELSIF ( mv.type == 'replacementprice' ) %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js index 3e8f312d274..494bc4e8a75 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js +++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js @@ -188,6 +188,20 @@ $(document).ready(function () { decimal_rate: true, }); + jQuery.validator.addMethod( + "replacement_price_decimal_rate", + function (value, element) { + return ( + this.optional(element) || /^\d{1,6}(\.\d{1,2})?$/.test(value) + ); + }, + __("Please enter up to 6 digits before the decimal and 2 digits after.") + ); + + jQuery.validator.addClassRules("replacement_price_decimal", { + replacement_price_decimal_rate: true, + }); + $("#logout").on("click", function () { logOut(); }); -- 2.34.1