luci-base: ui.js: allow custom validation in Dropdown and DynamicList
authorJo-Philipp Wich <jo@mein.io>
Mon, 16 Dec 2019 16:44:27 +0000 (17:44 +0100)
committerJo-Philipp Wich <jo@mein.io>
Mon, 16 Dec 2019 16:46:01 +0000 (17:46 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/ui.js

index 31f89339c4fdbb4545d478ff84a4ba1894a8783f..a60aea9119f67c43820fbd8b6f3637d44bde384f 100644 (file)
@@ -457,9 +457,9 @@ var UIDropdown = UIElement.extend({
                                'placeholder': this.options.custom_placeholder || this.options.placeholder
                        });
 
-                       if (this.options.datatype)
-                               L.ui.addValidator(createEl, this.options.datatype,
-                                                 true, null, 'blur', 'keyup');
+                       if (this.options.datatype || this.options.validate)
+                               L.ui.addValidator(createEl, this.options.datatype || 'string',
+                                                 true, this.options.validate, 'blur', 'keyup');
 
                        sb.lastElementChild.appendChild(E('li', { 'data-value': '-' }, createEl));
                }
@@ -1270,9 +1270,9 @@ var UIDynamicList = UIElement.extend({
                        dl.lastElementChild.appendChild(inputEl);
                        dl.lastElementChild.appendChild(E('div', { 'class': 'cbi-button cbi-button-add' }, '+'));
 
-                       if (this.options.datatype)
-                               L.ui.addValidator(inputEl, this.options.datatype,
-                                                 true, null, 'blur', 'keyup');
+                       if (this.options.datatype || this.options.validate)
+                               L.ui.addValidator(inputEl, this.options.datatype || 'string',
+                                                 true, this.options.validate, 'blur', 'keyup');
                }
 
                for (var i = 0; i < this.values.length; i++)