Bug 11771 - Use validation plugin when creating new MARC framework tag
authorOwen Leonard <oleonard@myacpl.org>
Fri, 14 Feb 2014 21:24:10 +0000 (16:24 -0500)
committerGalen Charlton <gmc@esilibrary.com>
Wed, 19 Feb 2014 00:03:24 +0000 (00:03 +0000)
The page for adding a new tag to a MARC 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 creation out of the script and into
the template where it belongs.

To test, apply the patch and go to Administration -> MARC bibliographic
framework -> 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>
Great improvement! Before this patch, I got a JS alert but the form was
submitted anyway.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
admin/marctagstructure.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/marctagstructure.tt

index 0326b93..d3b227d 100755 (executable)
@@ -126,16 +126,8 @@ if ($op eq 'add_form') {
        $template->param('use_heading_flags_p' => 1);
        $template->param(liblibrarian => $data->{'liblibrarian'},
                        libopac => $data->{'libopac'},
-                       repeatable => CGI::checkbox(-name=>'repeatable',
-                                               -checked=> $data->{'repeatable'}?'checked':'',
-                                               -value=> 1,
-                                               -label => '',
-                                               -id=> 'repeatable'),
-                       mandatory => CGI::checkbox(-name => 'mandatory',
-                                               -checked => $data->{'mandatory'}?'checked':'',
-                                               -value => 1,
-                                               -label => '',
-                                               -id => 'mandatory'),
+            repeatable => $data->{'repeatable'},
+            mandatory => $data->{'mandatory'},
                        authorised_value => $authorised_value,
                        frameworkcode => $frameworkcode,
     );  # FIXME: move checkboxes to presentation layer
index c905f30..7ce8414 100644 (file)
 
 <script type="text/javascript">
 //<![CDATA[
-function Check(f) {
-    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);
-    }
-}
 
 $(document).ready(function() {
     $("#table_marctagstructure").dataTable($.extend(true, {}, dataTablesDefaults, {
@@ -76,20 +61,32 @@ $(document).ready(function() {
 
 [% IF ( add_form ) %]
 
-    <form action="[% script_name %]" name="Aform" method="post">
+    <form action="[% script_name %]" name="Aform" method="post" class="validated">
        
       <fieldset class="rows"><legend>[% IF ( use_heading_flags_p ) %][% IF ( heading_modify_tag_p ) %]Modify tag <input type="hidden" name="modif" value="1" />[% searchfield %][% END %][% IF ( heading_add_tag_p ) %]Add tag[% END %][% ELSE %][% action %][% END %]</legend>  <input type="hidden" name="op" value="add_validate" />
        <input type="hidden" name="frameworkcode" value="[% frameworkcode %]" />
 
-       <ol> <li><label for="tagfield">Tag: </label><input id="tagfield" type="text" name="tagfield" value="[% searchfield %]" maxlength="3" size="3" /></li>    
+    <ol> <li><label for="tagfield" class="required">Tag: </label><input id="tagfield" type="text" name="tagfield" value="[% searchfield %]" maxlength="3" size="3" required="required" class="required" /> <span class="required">Required</span></li>
     <li><label for="liblibrarian">Label for lib: </label><input type="text" id="liblibrarian" name="liblibrarian" value="[% liblibrarian |html %]" size="40" maxlength="100" /></li>
     <li><label for="libopac">Label for opac: </label><input type="text" id="libopac" name="libopac" value="[% libopac |html %]" size="40" maxlength="100" /></li>
-    <li><label for="repeatable">Repeatable: </label>[% repeatable %]</li>
-    <li><label for="mandatory">Mandatory: </label>[% mandatory %]</li>
+    <li><label for="repeatable">Repeatable: </label>
+        [% IF ( repeatable ) %]
+            <input type="checkbox" name="repeatable" id="repeatable" value="1" checked="checked" />
+        [% ELSE %]
+            <input type="checkbox" name="repeatable" id="repeatable" value="1" />
+        [% END %]
+    </li>
+    <li><label for="mandatory">Mandatory: </label>
+        [% IF ( mandatory ) %]
+            <input type="checkbox" name="mandatory" id="mandatory" value="1" checked="checked" />
+        [% ELSE %]
+            <input type="checkbox" name="mandatory" id="mandatory" value="1" />
+        [% END %]
+    </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> 
     <fieldset class="action">
-        <input type="submit" value="Save Changes" onclick="Check(this.form)" />
+        <input type="submit" value="Save changes" />
         <a class="cancel" href="[% script_name %]?frameworkcode=[% frameworkcode %]">Cancel</a>
     </fieldset>
     </form>