Bugzilla – Attachment 191261 Details for
Bug 38839
Add validation for replacement price in item input form
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38839: Added "decimal" validation for replacement price in item and batch modification forms.
Bug-38839-Added-decimal-validation-for-replacement.patch (text/plain), 7.26 KB, created by
Lari Taskula
on 2026-01-12 14:32:09 UTC
(
hide
)
Description:
Bug 38839: Added "decimal" validation for replacement price in item and batch modification forms.
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2026-01-12 14:32:09 UTC
Size:
7.26 KB
patch
obsolete
>From 1deb225616a62734187bf745cb1e42c136d635ba Mon Sep 17 00:00:00 2001 >From: Leo Stoyanov <leo.stoyanov@bywatersolutions.com> >Date: Fri, 10 Jan 2025 23:01:17 +0000 >Subject: [PATCH] Bug 38839: Added "decimal" validation for replacement price > in item and batch modification forms. > >Adds validation for the replacement price on the item input and batch modification forms. > >This new patch utilizes the standard jQuery "decimal" validator to check if monetary input is appropriatly formatted. > >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) and restart everything (restart_all). >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. >--- > Koha/UI/Form/Builder/Item.pm | 6 +++ > .../prog/en/includes/html_helpers.inc | 10 ++++ > .../prog/en/modules/cataloguing/additem.tt | 2 +- > .../prog/en/modules/tools/batchMod-edit.tt | 2 +- > t/db_dependent/Koha/UI/Form/Builder/Item.t | 48 ++++++++++++++++++- > 5 files changed, 64 insertions(+), 4 deletions(-) > >diff --git a/Koha/UI/Form/Builder/Item.pm b/Koha/UI/Form/Builder/Item.pm >index 033037d43d9..a4c6490a7ab 100644 >--- a/Koha/UI/Form/Builder/Item.pm >+++ b/Koha/UI/Form/Builder/Item.pm >@@ -368,6 +368,12 @@ sub generate_subfield_form { > id => $subfield_data{id}, > value => $value, > }; >+ } elsif ( $subfield->{kohafield} =~ /items\.(replacementprice)/ ) { >+ $subfield_data{marc_value} = { >+ type => 'replacementprice', >+ id => $subfield_data{id}, >+ value => $value >+ }; > } else { > > # it's a standard field >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 f3924534546..d0d1484606e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc >@@ -235,6 +235,16 @@ > data-flatpickr-enable-time="true" > data-flatpickr-set-to-today="true" > /> >+ [% ELSIF ( mv.type == 'replacementprice' ) %] >+ <input >+ class="decimal valid input_marceditor [% kohafield | html %]" >+ type="text" >+ id="[% mv.id | html %]" >+ name="[% kohafield | html %]" >+ value="[% mv.value | html %]" >+ maxlength="[%- mv.maxlength | html -%]" >+ aria-invalid="false" >+ /> > [% END %] > > [% IF subfield.kohafield == 'items.more_subfields_xml' %] >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 76758d3deb6..0ed438293c0 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt >@@ -229,7 +229,7 @@ > <div class="col-md-2 order-sm-2 order-md-1"> [% INCLUDE 'biblio-view-menu.inc' %] </div> > <div class="col-md-10 order-md-2 order-sm-1"> > <div id="cataloguing_additem_newitem" class="item_edit_form page-section marc_editor"> >- <form id="f" method="post" action="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblio.biblionumber | html %]" name="f"> >+ <form id="f" method="post" action="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblio.biblionumber | html %]" name="f" class="validated"> > [% INCLUDE 'csrf-token.inc' %] > <input type="hidden" name="op" value="[% op | html %]" /> > [% IF (popup) %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt >index 1d5511c9a49..5b26678ee09 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt >@@ -162,7 +162,7 @@ > [% END %] > [% END # /IF notfounditemnumbers.size %] > >- <form name="f" action="batchMod.pl" method="post"> >+ <form name="f" action="batchMod.pl" method="post" class="validated"> > [% INCLUDE 'csrf-token.inc' %] > <input type="hidden" name="op" value="[% op | html %]" /> > <input type="hidden" name="searchid" value="[% searchid | html %]" /> >diff --git a/t/db_dependent/Koha/UI/Form/Builder/Item.t b/t/db_dependent/Koha/UI/Form/Builder/Item.t >index 2eab4bfcec1..e4c5968ddb8 100755 >--- a/t/db_dependent/Koha/UI/Form/Builder/Item.t >+++ b/t/db_dependent/Koha/UI/Form/Builder/Item.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > use Test::NoWarnings; >-use Test::More tests => 11; >+use Test::More tests => 12; > use Test::MockModule; > use Data::Dumper qw( Dumper ); > use utf8; >@@ -83,7 +83,7 @@ subtest 'authorised values' => sub { > $subfield->{marc_value}->{values}, > [ > "", >- map { $_->authorised_value } >+ map { $_->authorised_value } > sort { $a->lib cmp $b->lib } $avs->as_list > ], > 'AVs are sorted by lib and en empty option is created first' >@@ -446,4 +446,48 @@ sub setup_mss { > tagfield => $itemtag, > } > )->update( { display_order => \['FLOOR( 1 + RAND( ) * 10 )'] } ); >+ >+ subtest 'replacementprice handling' => sub { >+ plan tests => 3; >+ >+ my $subfield = { >+ kohafield => 'items.replacementprice', >+ id => 'tag_952_subfield_v_12345', >+ value => '123.45', >+ }; >+ >+ my $expected_marc_value = { >+ type => 'replacementprice', >+ id => 'tag_952_subfield_v_12345', >+ value => '123.45', >+ }; >+ >+ my $item = Koha::Item->new(); >+ >+ my %subfield_data; >+ if ( $subfield->{kohafield} =~ /items\.(replacementprice)/ ) { >+ $subfield_data{marc_value} = { >+ type => 'replacementprice', >+ id => $subfield->{id}, >+ value => $subfield->{value}, >+ }; >+ } >+ >+ ok( >+ exists $subfield_data{marc_value}, >+ "Subfield data contains 'marc_value' key" >+ ); >+ >+ is( >+ $subfield_data{marc_value}->{type}, >+ $expected_marc_value->{type}, >+ "Subfield 'type' is correctly set to 'replacementprice'" >+ ); >+ >+ is_deeply( >+ $subfield_data{marc_value}, >+ $expected_marc_value, >+ 'Subfield data is processed correctly for replacementprice' >+ ); >+ }; > } >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 38839
:
176279
|
176285
|
176286
|
176403
|
176407
|
176839
|
177093
| 191261 |
191262
|
191263