Bug 11789 - Use validation plugin when creating new list
authorOwen Leonard <oleonard@myacpl.org>
Tue, 18 Feb 2014 20:37:31 +0000 (15:37 -0500)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 21 Feb 2014 20:14:00 +0000 (20:14 +0000)
The page for adding a new list 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.

Other edits: Minor validation fixes.

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

Submission of the form with valid data should work correctly. Editing an
existing list 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>
koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt

index 95fa4b9..aca9485 100644 (file)
@@ -155,26 +155,7 @@ function placeHold () {
     $("#hold_form").submit();
     return false;
 }
-    /**
-     * This function checks to make sure a list title is assigned
-     */
-      function Check(f) {
-               var _alertString="";
-               var alertString2;
-
-           if($("#shelfname").val() == ""){
-            _alertString += "- "+_("You must enter a List Name") + "\n";
-               }
 
-               if (_alertString.length==0) {
-            f.submit();
-               } else {
-                       alertString2 = _("Form not submitted because of the following problem(s)");
-                       alertString2 += "\n------------------------------------------------------------------------------------\n\n";
-                       alertString2 += _alertString;
-                       alert(alertString2);
-               }
-       }
     function cartList(){
         var checkboxes = $("#searchresults").find(":checkbox");
         var vshelf = vShelfAdd(checkboxes);
@@ -440,14 +421,16 @@ function placeHold () {
 [% IF ( seflag ) %]
 <div class="yui-ge">
     <div class="yui-u first">
-    <form method="post" action="/cgi-bin/koha/virtualshelves/shelves.pl">
+    <form method="post" action="/cgi-bin/koha/virtualshelves/shelves.pl" class="validated">
         <fieldset class="rows">
 
     [% IF ( shelves ) %]
-        <input type="hidden" name="shelves" value="1" />
         <legend>Create a new list</legend>
+        <input type="hidden" name="shelves" value="1" />
         <ol>
-        <li><label class="required" for="addshelf">List name:</label><input id="addshelf" type="text" name="addshelf" size="25" /></li>
+        <li><label class="required" for="addshelf">List name:</label><input id="addshelf" type="text" name="addshelf" size="25" required="required" class="required" />
+            <span class="required">Required</span>
+        </li>
         <li><span class="label">Owner: </span><input type="hidden" name="owner" id="owner" value="[% loggedinuser %]" />[% loggedinusername %]</li>
         <li><label for="sortfield" >Sort this list by: </label>
         <select name="sortfield" id="sortfield">
@@ -466,13 +449,15 @@ function placeHold () {
     [% END %]
 
     [% IF ( edit ) %]
-               <input type="hidden" name="op" value="modifsave" />
+        <legend>Edit list <i>[% shelfname | html %]</i></legend>
         <input type="hidden" name="display" value="[% display %]" />
+        <input type="hidden" name="op" value="modifsave" />
         [% IF ( showprivateshelves ) %]<input type="hidden" name="display" value="privateshelves" />[% END %]
-               <input type="hidden" name="shelfnumber" value="[% shelfnumber %]" />
-        <legend>Edit list <i>[% shelfname | html %]</i></legend>
+        <input type="hidden" name="shelfnumber" value="[% shelfnumber %]" />
                <ol>
-               <li><label for="shelfname">Name: </label><input type="text" id="shelfname" name="shelfname" size="25" value="[% shelfname |html %]" /></li>
+            <li><label for="shelfname" class="required">Name: </label><input type="text" id="shelfname" name="shelfname" size="25" value="[% shelfname |html %]" required="required" class="required" />
+            <span class="required">Required</span>
+        </li>
                <li><label for="owner">Owner: </label><input type="hidden" id="owner" name="owner" value="[% IF ( owner ) %][% ownername %][% ELSE %][% loggedinusername %][% END %]" />[% IF ( owner ) %][% ownername %][% ELSE %][% loggedinusername %][% END %]</li>
                <li><label for="sortfield" >Sort this list by: </label>
                <select name="sortfield">
@@ -499,7 +484,8 @@ function placeHold () {
        [% END %]
 
                </fieldset>
-               <fieldset class="action"><input type="submit" onclick="Check(this.form); return false;" value="Save" class="submit" />
+
+    <fieldset class="action"><input type="submit" value="Save" class="submit" />
         [% IF ( showprivateshelves ) %]
             <a href="/cgi-bin/koha/virtualshelves/shelves.pl?display=privateshelves" class="cancel">Cancel</a>
         [% ELSE %]
@@ -516,7 +502,6 @@ function placeHold () {
         <div class="help"><ul>
             <li>A <b>Private</b> list is managed by you and can be seen only by you.</li>
             <li> A <b>Public</b> list can be seen by everybody, but managed only by you.</li>
-            <br/>
             <li>The owner of a list is always allowed to add entries, but needs permission to remove.</li>
         </ul>
         </div>