From: Helge Mader Date: Fri, 12 Mar 2021 14:47:38 +0000 (+0100) Subject: luci-base: prevent empty field for adding new named section in JavaScript X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=56f453ad13c8b5a0954123ac15c4a95b1d64ea17;p=project%2Fluci.git luci-base: prevent empty field for adding new named section in JavaScript Suggested-by: Helge Mader Signed-off-by: Florian Eckert (cherry picked from commit 87215e3d1bd2406c4a5ae5088e176fb4aefbe546) --- diff --git a/modules/luci-base/htdocs/luci-static/resources/form.js b/modules/luci-base/htdocs/luci-static/resources/form.js index 29e8fa7f05..e9c8d2eb00 100644 --- a/modules/luci-base/htdocs/luci-static/resources/form.js +++ b/modules/luci-base/htdocs/luci-static/resources/form.js @@ -2212,11 +2212,21 @@ var CBITypedSection = CBIAbstractSection.extend(/** @lends LuCI.form.TypedSectio return this.handleAdd(ev, nameEl.value); }), - 'disabled': this.map.readonly || null + 'disabled': true }, [ btn_title || _('Add') ]) ]); - ui.addValidator(nameEl, 'uciname', true, 'blur', 'keyup'); + ui.addValidator(nameEl, 'uciname', true, function(v) { + var button = document.querySelector('.cbi-section-create > .cbi-button-add'); + if (v !== '') { + button.disabled = false; + return true; + } + else { + button.disabled = true; + return _('Expecting: %s').format(_('non-empty value')); + } + }, 'blur', 'keyup'); } return createEl;