luci-base: ui.js: mark widget optional if empty choice is present
authorJo-Philipp Wich <jo@mein.io>
Sun, 28 Jul 2019 15:24:12 +0000 (17:24 +0200)
committerJo-Philipp Wich <jo@mein.io>
Thu, 1 Aug 2019 14:45:54 +0000 (16:45 +0200)
Fixes: #2943
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/ui.js

index f6a964fb10b4247351fd4c3f74aeeca17694a57e..fd413042f9aa13a12079abdf023f9c0a2939a061 100644 (file)
@@ -223,6 +223,9 @@ var UISelect = UIElement.extend({
                        widget: 'select',
                        orientation: 'horizontal'
                }, options);
+
+               if (this.choices.hasOwnProperty(''))
+                       this.options.optional = true;
        },
 
        render: function() {
@@ -243,7 +246,7 @@ var UISelect = UIElement.extend({
                                'multiple': this.options.multiple ? '' : null
                        }));
 
-                       if (this.options.optional || this.choices.hasOwnProperty(''))
+                       if (this.options.optional)
                                frameEl.lastChild.appendChild(E('option', {
                                        'value': '',
                                        'selected': (this.values.length == 0 || this.values[0] == '') ? '' : null