Enforce valid phone numbers in user settings
authorJeff Godin <jgodin@tadl.org>
Mon, 22 Jun 2015 19:21:09 +0000 (15:21 -0400)
committerJeff Godin <jgodin@tadl.org>
Mon, 22 Jun 2015 19:21:09 +0000 (15:21 -0400)
Enforce valid phone numbers in user settings by preventing a save of
the user if the widgets are not considered isValid.

Also, since the staff client doesn't seem to style yellow when we're
asking it to, use an alert() for invalid data.

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Open-ILS/web/js/ui/default/actor/user/register.js

index a82da9f..3012e10 100644 (file)
@@ -991,6 +991,11 @@ function uEditDrawSettingRow(tbody, dividerRow, template, stype) {
         case 'opac.default_phone':
             var tb = new dijit.form.TextBox({scrollOnFocus:false}, getByName(row, 'widget'));
             tb.attr('value', userSettings[stype.name()]);
+            tb.isValid = function() {
+                if (this.value.match(/^\s*$/) || this.value.match(/^\d{3}-\d{3}-\d{4}$/)) {
+                    return true;
+                }
+            };
             if (stype.name() === 'opac.default_sms_notify') {
                 dojo.create("div", {innerHTML: "<img id='sms_lookup_result'></img>"}, row);
             }
@@ -1016,6 +1021,7 @@ function uEditDrawSettingRow(tbody, dividerRow, template, stype) {
                     }
                 } else {
                     dojo.style(tb.domNode, "background-color", "yellow");
+                    alert("Invalid value for " + stype.label());
                 }
                 userSettingsToUpdate[stype.name()] = newVal; });
             break;