From b1ee48abf81c7d00febd45c2cf2f503c36872a7f 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. --- .../intranet-tmpl/prog/en/includes/html_helpers.inc | 2 +- koha-tmpl/intranet-tmpl/prog/js/staff-global.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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 2a3b47ef17..5ec9045714 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc @@ -171,7 +171,7 @@ [% ELSIF ( mv.type == 'datetime_field' ) %] [% ELSIF ( mv.type == 'replacementprice' ) %] - + [% END %] [% IF subfield.kohafield == 'items.more_subfields_xml' %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js index e76bf876f6..2e0d6d0afd 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js +++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js @@ -157,6 +157,15 @@ $(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.39.5