luci-base: show validation message in error
[project/luci.git] / modules / luci-base / htdocs / luci-static / resources / ui.js
index 9cc62c12db1a1612e21e07811c6a9dba9af32f8c..9f3e74b93562a912669f6dcb82b527c8da671136 100644 (file)
@@ -155,6 +155,18 @@ var UIElement = baseclass.extend(/** @lends LuCI.ui.AbstractElement.prototype */
                return (this.validState !== false);
        },
 
+       /**
+        * Returns the current validation error
+        *
+        * @instance
+        * @memberof LuCI.ui.AbstractElement
+        * @returns {string}
+        * The validation error at this time
+        */
+       getValidationError: function() {
+               return this.validationError || '';
+       },
+
        /**
         * Force validation of the current input value.
         *
@@ -243,10 +255,12 @@ var UIElement = baseclass.extend(/** @lends LuCI.ui.AbstractElement.prototype */
 
                this.node.addEventListener('validation-success', L.bind(function(ev) {
                        this.validState = true;
+                       this.validationError = '';
                }, this));
 
                this.node.addEventListener('validation-failure', L.bind(function(ev) {
                        this.validState = false;
+                       this.validationError = ev.detail.message;
                }, this));
        },