luci-base: do not add validation for named section if readonly is set
authorFlorian Eckert <fe@dev.tdt.de>
Thu, 1 Jul 2021 13:54:21 +0000 (15:54 +0200)
committerJo-Philipp Wich <jo@mein.io>
Wed, 7 Jul 2021 15:18:19 +0000 (17:18 +0200)
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
(cherry picked from commit 1a2b7fef6cc181f7f0ff0e1133ad4d8ab03e279c)

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

index e9c8d2eb00dd44b2da968e5228cab80ffca54135..fbdd73e55e211c567640b3280e5f09207efe0890 100644 (file)
@@ -2212,21 +2212,23 @@ var CBITypedSection = CBIAbstractSection.extend(/** @lends LuCI.form.TypedSectio
 
                                                return this.handleAdd(ev, nameEl.value);
                                        }),
-                                       'disabled': true
+                                       'disabled': this.map.readonly || true
                                }, [ btn_title || _('Add') ])
                        ]);
 
-                       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');
+                       if (this.map.readonly !== true) {
+                               ui.addValidator(nameEl, 'uciname', true, function(v) {
+                                       var button = document.querySelector('.cbi-section-create > .cbi-button-add');
+                                       if (v !== '') {
+                                               button.disabled = null;
+                                               return true;
+                                       }
+                                       else {
+                                               button.disabled = true;
+                                               return _('Expecting: %s').format(_('non-empty value'));
+                                       }
+                               }, 'blur', 'keyup');
+                       }
                }
 
                return createEl;