LP#1098685 Html5 form validation to require OPAC patron enter hold SMS info
authorCesar Velez <cesar.velez@equinoxinitiative.org>
Wed, 24 May 2017 15:56:37 +0000 (11:56 -0400)
committerCesar Velez <cesar.velez@equinoxinitiative.org>
Wed, 24 May 2017 15:56:37 +0000 (11:56 -0400)
This uses Html5 form validation's require attribute that's supported since IE10.
Will add custom Modernizer detect and polyfill that allows for more backward compatibility older browsers.

Signed-off by: Cesar Velez <cesar.velez@equinoxinitiative.org>

Open-ILS/src/templates/opac/parts/js.tt2
Open-ILS/src/templates/opac/parts/place_hold.tt2

index f7fc737..845eed2 100644 (file)
@@ -151,6 +151,32 @@ var aou_hash = {
           return false;
         }
      }
+
+    function onHoldAlertMethodChanged(cbox){
+        
+        switch(cbox.id){
+            case "phone_notify_checkbox":
+                var phoneInput = document.getElementsByName("phone_notify")[0];
+                if(cbox.checked) {
+                    phoneInput.setAttribute("required","");
+                } else {
+                    phoneInput.removeAttribute("required");
+                }
+                break;
+            case "sms_notify_checkbox":
+                var smsInput = document.getElementsByName("sms_notify")[0];
+                var carrierInput = document.getElementsByName("sms_carrier")[0];
+                if(cbox.checked) {
+                    smsInput.setAttribute("required","");
+                    carrierInput.setAttribute("required","");
+                } else {
+                    smsInput.removeAttribute("required");
+                    carrierInput.removeAttribute("required");
+                }
+                break;
+        }
+    }
+        
   </script>
 [% END %]
 
index 8bf1713..716b120 100644 (file)
         <p>
             [% l('Notify when hold is ready for pickup?') %]
             <blockquote>
-                <input type="checkbox" id="email_notify" name="email_notify" value="t"
+                <input class="hold-alert-method" type="checkbox" id="email_notify" name="email_notify" value="t"
                     [% IF !ctx.user.email %]disabled="true"[% ELSIF ctx.default_email_notify %]checked="checked"[% END %]/>
                     <label for="email_notify">[% l('Yes, by Email') %]</label><br/>
                 <blockquote>
                      ELSE; l('Email Address:') %] <span name="email_address">[% ctx.user.email %]</span>[% END %]
                 </blockquote>
                 [%- IF allow_phone_notifications == 'true' %]
-                <input type="checkbox" id="phone_notify_checkbox" name="phone_notify_checkbox"
+                <input onchange="onHoldAlertMethodChanged(this)" class="hold-alert-method" type="checkbox" id="phone_notify_checkbox" name="phone_notify_checkbox"
+
+
                     [% IF ctx.default_phone_notify %]checked="checked"[% END %]/>
                     <label for="phone_notify_checkbox">[% l('Yes, by Phone') %]</label><br/>
                 <blockquote>
                 </blockquote>
                 [%- END -%]
                 [% IF ctx.get_org_setting(ctx.search_ou, 'sms.enable') == 1 %]
-                <input type="checkbox" id="sms_notify_checkbox" name="sms_notify_checkbox"
+                <input onchange="onHoldAlertMethodChanged(this)" class="hold-alert-method" type="checkbox" id="sms_notify_checkbox" name="sms_notify_checkbox"
                     [% IF ctx.default_sms_notify %]checked="checked"[% END %]/>
                     <label for="sms_notify_checkbox">[% l('Yes, by Text Messaging') %]</label><br/>
                 <blockquote>