[Koha-bugs] [Bug 34169] Add pattern check for monetary fields to acquisition module

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Tue Jul 11 14:38:49 CEST 2023


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34169

--- Comment #2 from Katrin Fischer <katrin.fischer at bsz-bw.de> ---
I tried to write a POC using jQuery starting with the normal acq order form:

$("#acq_neworderempty #unitprice").attr({inputmode: "decimal", pattern:
"^\d+(\.\d{2})?$" });

It didn't work there, because we use the validate JS plugin.

But we could maybe use that to our advantage. With Joubu's help:

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt
b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt
index 42f537a5924..7f0be4c0af2 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt
@@ -669,7 +669,7 @@
             </li>
             <li class="ordering_unitprice">
                 <label for="unitprice">Actual cost: </label>
-                <input type="text" id="unitprice" size="20" name="unitprice"
value="[% unitprice | html %]" />
+                <input type="text" id="unitprice" size="20" name="unitprice"
value="[% unitprice | html %]" class="price" />
                 [% IF (invoiceincgst == 1) %](tax inc.)[% ELSE %](tax exc.)[%
END %]
             </li>
             <li>
diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
index 74af1ad89ae..aeab2be8667 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
@@ -110,6 +110,9 @@ $(document).ready(function() {
     $(".validated").each(function() {
         $(this).validate();
     });
+    jQuery.validator.addClassRules("price", {
+        number: true
+    });

     $("#logout").on("click",function(){
         logOut();

* It allows to add negative and positive amounts with decimal dot. This is OK
as we do need the ability to add negatives in acquisitions. 
* It does allow entering thousand separators with a ., but Koha hates it and
won't save the value:

check_budget_total.pl:
XML Parsing Error: syntax error
Location:
http://localhost:8081/cgi-bin/koha/acqui/check_budget_total.pl?budget_id=2&total=21.60
Line Number 1, Column 1:

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are watching all bug changes.


More information about the Koha-bugs mailing list