From 87215e3d1bd2406c4a5ae5088e176fb4aefbe546 Mon Sep 17 00:00:00 2001 From: Helge Mader Date: Fri, 12 Mar 2021 15:47:38 +0100 Subject: [PATCH] luci-base: prevent empty field for adding new named section in JavaScript Suggested-by: Helge Mader Signed-off-by: Florian Eckert --- .../luci-base/htdocs/luci-static/resources/form.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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; -- 2.30.2