luci-base: prevent empty field for adding new named section in JavaScript
authorHelge Mader <ma@dev.tdt.de>
Fri, 12 Mar 2021 14:47:38 +0000 (15:47 +0100)
committerJo-Philipp Wich <jo@mein.io>
Wed, 7 Jul 2021 15:18:16 +0000 (17:18 +0200)
Suggested-by: Helge Mader <ma@dev.tdt.de>
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
(cherry picked from commit 87215e3d1bd2406c4a5ae5088e176fb4aefbe546)

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

index 29e8fa7f05575ab762e9fa74cb655ae4a95346a6..e9c8d2eb00dd44b2da968e5228cab80ffca54135 100644 (file)
@@ -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;