[Koha-patches] [PATCH] Bug 11787 - Use validation plugin when adding new vendor

Owen Leonard oleonard at myacpl.org
Tue Feb 18 21:14:37 CET 2014


The vendor entry form uses some custom JavaScript which can be removed
in favor of HTML5 validation attributes and Koha's built-in validation
plugin. This patch does so.

Also corrected: Minor validation issue.

To test, apply the patch and go to Acquisitions -> New vendor. Try
submitting the form without entering a vendor name. This should trigger
a validation warning.

Submission of the form with valid data should work correctly. Editing an
existing vendor should also work correctly.
---
 .../prog/en/modules/acqui/supplier.tt              |   21 +++++++-------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt
index 79ae629..14faa11 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt
@@ -12,13 +12,6 @@ function confirm_deletion() {
         window.location="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid %]&op=delete";
     }
 }
-function check(f) {
-if (f.company.value == "") {
-    alert(_("You must specify a name for this vendor."));
-    return false;
-}
-    f.submit();
-}
 
  $(document).ready(function() {
     [% IF (dateformat == 'metric') %]
@@ -60,13 +53,13 @@ if (f.company.value == "") {
     [% END %]
 [% UNLESS ( enter ) %][% INCLUDE 'acquisitions-toolbar.inc' %][% END %]
 [% IF ( enter ) %]
-    <form action="updatesupplier.pl" name="updatesupplier" method="post">
+    <form action="updatesupplier.pl" name="updatesupplier" class="validated" method="post">
     <div class="yui-g">
         <input type="hidden" name="booksellerid" value="[% booksellerid %]" />
         <fieldset class="rows">
             <legend>Company details</legend>
-            <ol><li><label for="company" class="required">Name: * </label>
-                <input type="text" size="40" id="company" name="company" value="[% name %]" class="focus" /></li>
+            <ol><li><label for="company" class="required">Name:</label>
+                <input type="text" size="40" id="company" name="company" value="[% name %]" required="required" class="required" /><span class="required">Required</span></li>
             <li><label for="company_postal">Postal address: </label>
                     <textarea id="company_postal" name="company_postal" cols="40" rows="3">[% postal %]</textarea></li>
             <li><label for="physical">Physical address: </label>
@@ -114,7 +107,7 @@ if (f.company.value == "") {
             <li><label for="list_currency">List prices are: </label>
                     <select name="list_currency" id="list_currency">
                     [% FOREACH loop_currenc IN loop_currency %]
-                        [% IF ( loop_currenc.listprice ) %]<option value="[% loop_currenc.currency %]" selected="1">[% loop_currenc.currency %]</option>
+                        [% IF ( loop_currenc.listprice ) %]<option value="[% loop_currenc.currency %]" selected="selected">[% loop_currenc.currency %]</option>
                         [% ELSE %]<option value="[% loop_currenc.currency %]">[% loop_currenc.currency %]</option>[% END %]
                     [% END %]
                     </select>
@@ -122,7 +115,7 @@ if (f.company.value == "") {
             <li><label for="invoice_currency">Invoice prices are: </label>
                     <select name="invoice_currency" id="invoice_currency">
                     [% FOREACH loop_currenc IN loop_currency %]
-                        [% IF ( loop_currenc.invoiceprice ) %]<option value="[% loop_currenc.currency %]" selected="1">[% loop_currenc.currency %]</option>
+                        [% IF ( loop_currenc.invoiceprice ) %]<option value="[% loop_currenc.currency %]" selected="selected">[% loop_currenc.currency %]</option>
                         [% ELSE %]<option value="[% loop_currenc.currency %]">[% loop_currenc.currency %]</option>[% END %]
                     [% END %]
                     </select>
@@ -159,7 +152,7 @@ if (f.company.value == "") {
             [% IF gst_values %]
                 <ol>
                   <li>
-                    <label for="gst">Tax rate: </label>
+                    <label for="gstrate">Tax rate: </label>
                     <select name="gstrate" id="gstrate">
                     [% FOREACH gst IN gst_values %]
                       [% IF ( gstrate == gst.option ) %]
@@ -184,7 +177,7 @@ if (f.company.value == "") {
             <li><label for="notes">Notes: </label>
                 <textarea cols="40" rows="4" id="notes" name="notes" >[% notes %]</textarea></li></ol>
         </fieldset>
-        <fieldset class="action"><input type="button" value="Save" onclick="check(this.form);" /> [% IF ( booksellerid ) %]
+        <fieldset class="action"><input type="submit" value="Save" /> [% IF ( booksellerid ) %]
         <a class="cancel" href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid %]">[% ELSE %]<a class="cancel" href="/cgi-bin/koha/acqui/acqui-home.pl">
         [% END %]Cancel</a></fieldset>
         </div>
-- 
1.7.9.5


More information about the Koha-patches mailing list