Bugzilla – Attachment 176407 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), 6.70 KB, created by
Leo Stoyanov
on 2025-01-11 17:51:26 UTC
(
hide
)
Description:
Bug 38839: Added "decimal" validation for replacement price in item and batch modification forms.
Filename:
MIME Type:
Creator:
Leo Stoyanov
Created:
2025-01-11 17:51:26 UTC
Size:
6.70 KB
patch
obsolete
>From 57c873f358a5999728c8e77f578b42d33f91bfaf 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 | 7 +++ > .../prog/en/includes/html_helpers.inc | 2 + > .../prog/en/modules/cataloguing/additem.tt | 2 +- > .../prog/en/modules/tools/batchMod-edit.tt | 2 +- > t/db_dependent/Koha/UI/Form/Builder/Item.t | 46 ++++++++++++++++++- > 5 files changed, 56 insertions(+), 3 deletions(-) > >diff --git a/Koha/UI/Form/Builder/Item.pm b/Koha/UI/Form/Builder/Item.pm >index cbc52522c3..c05fadeebd 100644 >--- a/Koha/UI/Form/Builder/Item.pm >+++ b/Koha/UI/Form/Builder/Item.pm >@@ -403,6 +403,13 @@ sub generate_subfield_form { > 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 > $subfield_data{marc_value} = { >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..f4f349282f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc >@@ -170,6 +170,8 @@ > <input type="text" id="[% mv.id | html %]" name="[% kohafield | html %]" class="input_marceditor [% kohafield | html %] flatpickr" value="[% mv.value | html %]" class="flatpickr" data-flatpickr-set-to-today="true" /> > [% ELSIF ( mv.type == 'datetime_field' ) %] > <input type="text" id="[% mv.id | html %]" name="[% kohafield | html %]" class="input_marceditor [% kohafield | html %] flatpickr" value="[% mv.value | html %]" 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 a41569fe99..5ef1388506 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt >@@ -199,7 +199,7 @@ > <div class="col-md-10 order-md-2 order-sm-1"> > > <div id="cataloguing_additem_newitem" class="item_edit_form page-section"> >- <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 b2b3161f21..66133df5e1 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 >@@ -156,7 +156,7 @@ > [% 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 251287a530..d63813f7af 100755 >--- a/t/db_dependent/Koha/UI/Form/Builder/Item.t >+++ b/t/db_dependent/Koha/UI/Form/Builder/Item.t >@@ -16,7 +16,7 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 10; >+use Test::More tests => 11; > use Test::MockModule; > use Data::Dumper qw( Dumper ); > use utf8; >@@ -456,3 +456,47 @@ sub setup_mss { > } > )->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.39.5
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