[Koha-patches] [PATCH] Bug 11770 - Use validation plugin when creating new road type

Owen Leonard oleonard at myacpl.org
Fri Feb 14 22:07:48 CET 2014


The page for adding a new road type 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 -> Road types -> New
road type. Try submitting the form without entering a road type. This
should trigger a validation warning.

Submission of the form with valid data should work correctly. Editing an
existing road type should also work correctly.
---
 .../prog/en/modules/admin/roadtype.tt              |   44 +++-----------------
 1 file changed, 5 insertions(+), 39 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/roadtype.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/roadtype.tt
index 526b445..03f67c0 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/roadtype.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/roadtype.tt
@@ -1,41 +1,6 @@
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha › Administration › [% IF ( add_form ) %]Road types › [% IF ( roadtypeid ) %] Modify road type[% ELSE %] New road type[% END %][% ELSE %][% IF ( delete_confirm ) %]Road types › Confirm deletion of road type[% ELSE %] Road type[% END %][% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript">
-//<![CDATA[
-        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-        function isNotNull(f,noalert) {
-                if (f.value.length == 0) {
-        return false;
-                }
-        return true;
-        }
-        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-        function isNum(v,maybenull) {
-        var n = new Number(v.value);
-        if (isNaN(n)) {
-                return false;
-                }
-        if (maybenull == 0 && v.value =='') {
-                return false;
-        }
-        return true;
-        }
-        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-        function Check(f) {
-                var ok=1;
-                var _alertString="";
-                var alertString2;
-                if (f.road_type.value.length == 0  ) {
-                        _alertString += "\n- " + _("Road type");
-                        alert(_alertString);	
-                }
-                else{
-                document.Aform.submit();
-                }
-        }
-//]]>
-</script>
 </head>
 <body id="admin_roadtype" class="admin">
 [% INCLUDE 'header.inc' %]
@@ -55,7 +20,7 @@
 		<h1>New road type</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="roadtypeid" value="[% roadtypeid %]" />
@@ -67,12 +32,13 @@
 	</li>
 [% END %]
 	<li>			
-		<label for="road_type">Road type: </label>
-	<input  type="text" name="road_type" id="road_type" size="80" maxlength="100" value="[% road_type |html %]" />
+        <label for="road_type" class="required">Road type: </label>
+        <input  type="text" name="road_type" id="road_type" size="80" maxlength="100" value="[% road_type |html %]" required="required" class="required" /> <span class="required">Required</span>
 	</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/roadtype.pl">Cancel</a>
+    <input class="button" type="submit" value="Submit" />
+    <a class="cancel" href="/cgi-bin/koha/admin/roadtype.pl">Cancel</a>
 	</fieldset>
 	</form>
 [% END %]
-- 
1.7.9.5


More information about the Koha-patches mailing list