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>
Thu, 7 May 2020 17:40:48 +0000 (19:40 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 90a161018c9c7650a27a66f8e0a4f060d1ccebd6)

modules/luci-base/htdocs/luci-static/resources/ui.js

index 272a4a840ea79d40a96c15a28639e42c77de88cd..dd5d963dd7ed8856ea99560bb3c00edbc41f09e7 100644 (file)
@@ -990,9 +990,9 @@ var UIDropdown = UIElement.extend(/** @lends LuCI.ui.Dropdown.prototype */ {
                                '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));
                }
@@ -2105,9 +2105,9 @@ var UIDynamicList = UIElement.extend(/** @lends LuCI.ui.DynamicList.prototype */
                        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++) {