luci-base: form.js: handle SectionValue objects in GridSection modals
[project/luci.git] / modules / luci-base / htdocs / luci-static / resources / validation.js
index 28042ba8cdb08fc1a06b6b95f1153b3812f94535..6dddf964fb93d21fb07518cdd52fcb6d7ffc4b50 100644 (file)
@@ -61,9 +61,15 @@ var Validator = baseclass.extend({
                        valid = this.vstack[0].apply(this, this.vstack[1]);
 
                if (valid !== true) {
-                       this.field.setAttribute('data-tooltip', _('Expecting: %s').format(this.error));
+                       var message = _('Expecting: %s').format(this.error);
+                       this.field.setAttribute('data-tooltip', message);
                        this.field.setAttribute('data-tooltip-style', 'error');
-                       this.field.dispatchEvent(new CustomEvent('validation-failure', { bubbles: true }));
+                       this.field.dispatchEvent(new CustomEvent('validation-failure', {
+                               bubbles: true,
+                               detail: {
+                                       message: message
+                               }
+                       }));
                        return false;
                }
 
@@ -74,7 +80,12 @@ var Validator = baseclass.extend({
                        this.assert(false, valid);
                        this.field.setAttribute('data-tooltip', valid);
                        this.field.setAttribute('data-tooltip-style', 'error');
-                       this.field.dispatchEvent(new CustomEvent('validation-failure', { bubbles: true }));
+                       this.field.dispatchEvent(new CustomEvent('validation-failure', {
+                               bubbles: true,
+                               detail: {
+                                       message: valid
+                               }
+                       }));
                        return false;
                }
 
@@ -338,9 +349,10 @@ var ValidatorFactory = baseclass.extend({
                        return this.assert(this.apply('port'), _('valid port or port range (port1-port2)'));
                },
 
-               macaddr: function() {
-                       return this.assert(this.value.match(/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/) != null,
-                               _('valid MAC address'));
+               macaddr: function(multicast) {
+                       var m = this.value.match(/^([a-fA-F0-9]{2}):([a-fA-F0-9]{2}:){4}[a-fA-F0-9]{2}$/);
+                       return this.assert(m != null && !(+m[1] & 1) == !multicast,
+                               multicast ? _('valid multicast MAC address') : _('valid MAC address'));
                },
 
                host: function(ipv4only) {
@@ -574,6 +586,18 @@ var ValidatorFactory = baseclass.extend({
 
                string: function() {
                        return true;
+               },
+
+               directory: function() {
+                       return true;
+               },
+
+               file: function() {
+                       return true;
+               },
+
+               device: function() {
+                       return true;
                }
        }
 });