Bug 11767 - Use validation plugin when creating new authority framework tag
authorOwen Leonard <oleonard@myacpl.org>
Fri, 14 Feb 2014 19:29:47 +0000 (14:29 -0500)
committerGalen Charlton <gmc@esilibrary.com>
Wed, 19 Feb 2014 15:51:12 +0000 (15:51 +0000)
The page for adding a new tag to an authority framework 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.

The patch also moves some tag markup out of the script and into the
template where it belongs.

To test, apply the patch and go to Administration -> Authority types ->
MARC structure -> New tag. Try submitting the form without entering a
tag number. This should trigger a validation warning.

Submission of the form with valid data should work correctly. Editing an
existing tag should also work correctly.

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
admin/auth_tag_structure.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_tag_structure.tt

index 31b510a..ae2d2da 100755 (executable)
@@ -111,18 +111,14 @@ if ($op eq 'add_form') {
             -id=>'authorised_value',
             -values=> \@authorised_values,
             -size=>1,
-            -tabindex=>'',
             -multiple=>0,
             -default => $data->{'authorised_value'},
             );
 
     if ($searchfield) {
-        $template->param(action => "Modify tag",
-                                searchfield => "<input type=\"hidden\" name=\"tagfield\" value=\"$searchfield\" />$searchfield");
+        $template->param('searchfield' => $searchfield);
         $template->param('heading_modify_tag_p' => 1);
     } else {
-        $template->param(action => "Add tag",
-                                searchfield => "<input type=\"text\" name=\"tagfield\" size=\"5\" maxlength=\"3\" />");
         $template->param('heading_add_tag_p' => 1);
     }
     $template->param('use_heading_flags_p' => 1);
index f8c3910..aed89bc 100644 (file)
         "sPaginationType": "four_button"
     }));
  });
-
-    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-    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.tagfield.value.length==0) {
-            _alertString += "\n- " + _("tag number missing");
-        }
-        if (_alertString.length==0) {
-            document.Aform.submit();
-        } else {
-            alertString2  = _("Form not submitted because of the following problem(s)");
-            alertString2 += "\n------------------------------------------------------------------------------------\n";
-            alertString2 += _alertString;
-            alert(alertString2);
-        }
-    }
-    //]]>
+//]]>
 </script>
 </head>
 <body id="admin_auth_tag_structure" class="admin">
@@ -112,17 +76,25 @@ return false;
 [% IF ( add_form ) %]
 
     <h2>
-    [% IF ( use_heading_flags_p ) %]
     [% IF ( heading_modify_tag_p ) %]Modify tag[% END %]
     [% IF ( heading_add_tag_p ) %]New tag[% END %]
-    [% ELSE %][% action %][% END %]
     </h2>
-    <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" />
         [% IF ( heading_modify_tag_p ) %]<input type="hidden" name="modif" value="1" />[% END %]
         <input type="hidden" name="authtypecode" value="[% authtypecode %]" />
-        <fieldset class="rows"><ol>
-        <li><span class="label">Tag: </span>[% searchfield %]</li>
+        <fieldset class="rows">
+            <ol>
+                [% IF ( heading_modify_tag_p ) %]
+                    <li>
+                        <span class="label">Tag: </span>
+                        <input type="hidden" name="tagfield" value="[% searchfield %]" />
+                        [% searchfield %]
+                    </li>
+                [% ELSE %]
+                    <li><label for="tagfield" class="required">Tag: </label><input type="text" id="tagfield" name="tagfield" size="5" maxlength="3" required="required" class="required" /></li>
+                [% END %]
+
         <li><label for="liblibrarian">Text for librarians: </label><input type="text" name="liblibrarian" id="liblibrarian" value="[% liblibrarian |html %]" size="40" maxlength="100" /></li>
         <li><label for="libopac">Text for opac: </label><input type="text" name="libopac" id="libopac" value="[% libopac |html %]" size="40" maxlength="100" /></li>
         <li><label for="repeatable">Repeatable: </label>
@@ -141,7 +113,10 @@ return false;
             </li>
         <li><label for="authorised_value">Authorized value: </label>[% authorised_value %] (if you select a value here, the indicators will be limited to the authorized value list)</li>
 </ol></fieldset>
-        <p><input type="button" value="Submit" class="button" onclick="Check(this.form)" /></p>
+        <fieldset class="action">
+            <input type="submit" value="Submit" />
+            <a href="/cgi-bin/koha/admin/auth_tag_structure.pl?authtypecode=[% authtypecode %]" class="cancel">Cancel</a>
+        </fieldset>
     </form>
 [% END %]