Bug 7670 - make required fields red
authorOwen Leonard <oleonard@myacpl.org>
Thu, 8 Mar 2012 13:53:45 +0000 (08:53 -0500)
committerPaul Poulain <paul.poulain@biblibre.com>
Fri, 16 Mar 2012 11:52:17 +0000 (12:52 +0100)
Adding "required" style and "Required" note to additem fields,
consistent with the way required fields are displayed
on the add patron form.

This patch also corrects an error in the client-side validation
script which misidentified which fields were required. Leaving
a required field empty should result in an alert and the missing
field being highlighted in yellow.

To test, open the add item form on a record which uses
a framework in which one or more item fields are required.
Required fields should be labeled in red and appended with a
"Required" note.

Submit the form while some required fields are empty. You should
see a javascript alert. The empty mandatory fields should have
a yellow background.

Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Works - passes tests.

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt

index b1c38f5..e8821f5 100644 (file)
@@ -1290,6 +1290,7 @@ div.note {
 
 span.required {
        font-style : italic;
+       margin-left : .5em;
 }
 
 .term {
index 91c2d48..008af82 100644 (file)
@@ -34,25 +34,24 @@ function active(numlayer)
     }
 }
 function Check(f) {
-
     var total_errors=0;
-//     alert(f.field_value.length);
-    for (i=0 ; i<f.field_value.length ; i++) {
-//     alert (f.field_value[i].value);
-        if (f.field_value[i].value.length==0 && f.mandatory[i].value==1) {
-            document.getElementById("error"+i).style.backgroundColor="#FF0000";
-            total_errors++;
-        } else {
-//                     document.getElementById("error"+i).style.backgroundColor="#FFFFFF";
+    $("input[name='mandatory'],select[name='mandatory']").each(function(i){
+        if($(this).val() == 1){
+            var mandatory_field = $("input[name='field_value'],select[name='field_value']").eq(i);
+            if(mandatory_field.val() == ''){
+                mandatory_field.css("background-color","#FFFFCC");
+                total_errors++;
+            }
         }
-    }
+    });
+
     var alertString2;
     if (total_errors==0) {
         return true;
     } else {
         alertString2  = _("Form not submitted because of the following problem(s)");
         alertString2 += "\n------------------------------------------------------------------------------------\n";
-        alertString2 += "\n- "+ total_errors+_(" mandatory fields empty (see bold subfields)");
+        alertString2 += "\n- "+ total_errors+_(" mandatory fields empty (highlighted)");
         alert(alertString2);
         return false;
     }
@@ -237,8 +236,11 @@ function set_to_today(id, force) {
        <ol>
         [% FOREACH ite IN item %]
                <li><div class="subfield_line" style="[% ite.visibility %]" id="subfield[% ite.tag %][% ite.subfield %][% ite.random %]">
-
-               <label>[% ite.subfield %] - [% IF ( ite.mandatory ) %]<b>[% END %][% ite.marc_lib %][% IF ( ite.mandatory ) %] *</b>[% END %]</label>
+                [% IF ( ite.mandatory ) %]
+               <label class="required">[% ite.subfield %] - [% ite.marc_lib %]</label>
+               [% ELSE %]
+               <label>[% ite.subfield %] - [% ite.marc_lib %]</label>
+               [% END %]
                 [% ite.marc_value %]
                 <input type="hidden" name="tag"       value="[% ite.tag %]" />
                 <input type="hidden" name="subfield"  value="[% ite.subfield %]" />
@@ -246,7 +248,7 @@ function set_to_today(id, force) {
                 [% IF ( ite.repeatable ) %]
                     <span class="buttonPlus" onclick="CloneSubfield('subfield[% ite.tag %][% ite.subfield %][% ite.random %]')">+</span>
                 [% END %]
-
+                [% IF ( ite.mandatory ) %] <span class="required">Required</span>[% END %]
             </div></li>
         [% END %]
     </ol>