luci-base: ui.js: mark widget optional if empty choice is present

Fixes: #2943
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-07-28 17:24:12 +02:00
parent b20f000c85
commit 360e9769d6

View file

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