[Koha-patches] [PATCH] Bug 11791 - Use validation plugin when creating new city

Owen Leonard oleonard at myacpl.org
Wed Feb 19 17:42:26 CET 2014


The page for adding a new city includes some custom form
validation JavaScript which can be removed in favor of HTML5 validation
attributes and Koha's built-in validation plugin. This patch does so.

To test, apply the patch and go to Administration -> Cities -> New city.
Try submitting the form without entering a city or zip code. This should
trigger a validation warning.

Submission of the form with valid data should work correctly. Editing an
existing city should also work correctly.
---
 .../intranet-tmpl/prog/en/modules/admin/cities.tt  |   19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cities.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cities.tt
index 8b8cc66..e6acddb 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cities.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cities.tt
@@ -5,13 +5,6 @@
 [% INCLUDE 'datatables.inc' %]
 <script type="text/javascript">
 //<![CDATA[
-    function Check(f) {
-        if (f.city_zipcode.value.length == 0 && f.city_name.value.length == 0 ) {
-            alert(_("City name & zipcode missing"));
-        } else{
-            document.Aform.submit();
-        }
-    }
     $(document).ready(function() {
         $("#table_cities").dataTable($.extend(true, {}, dataTablesDefaults, {
             "aoColumnDefs": [
@@ -53,7 +46,7 @@
 		<h1>New city</h1>
 	[% END %]
 
-	<form action="[% script_name %]" name="Aform" method="post">
+    <form action="[% script_name %]" name="Aform" method="post" class="validated">
 	<input type="hidden" name="op" value="add_validate" />
 	<input type="hidden" name="checked" value="0" />
 	<input type="hidden" name="cityid" value="[% cityid %]" />
@@ -63,16 +56,16 @@
 		<span class="label">City ID: </span>[% cityid %]</li>
 	[% END %]
 	<li>
-	<label for="city_name" class="required" title="required">City: </label>
-	<input type="text" name="city_name" id="city_name" size="80" maxlength="100" value="[% city_name |html %]" />
+    <label for="city_name" class="required">City: </label>
+    <input type="text" name="city_name" id="city_name" size="80" maxlength="100" value="[% city_name |html %]" required="required" class="required" /> <span class="required">Required</span>
 	</li>
 	<li>
 	<label for="city_state">State: </label>
 	<input type="text" name="city_state" id="city_state" size="80" maxlength="100" value="[% city_state |html %]" />
 	</li>
 	<li>				
-	<label for="city_zipcode" class="required" title="required">Zip/Postal code: </label>
-	<input type="text" name="city_zipcode" id="city_zipcode" size="20" maxlength="20" value="[% city_zipcode %]" />
+    <label for="city_zipcode" class="required">Zip/Postal code: </label>
+    <input type="text" name="city_zipcode" id="city_zipcode" size="20" maxlength="20" value="[% city_zipcode %]" required="required" class="required" /> <span class="required">Required</span>
 	</li>
 	<li>
 	<label for="city_country">Country: </label>
@@ -80,7 +73,7 @@
 	</li></ol></fieldset>
 	
 	<fieldset class="action">
-		<input class="button" type="button" onclick="Check(this.form)" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/admin/cities.pl">Cancel</a>
+        <input type="submit" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/admin/cities.pl">Cancel</a>
 	</fieldset>
 	</form>
 
-- 
1.7.9.5


More information about the Koha-patches mailing list