luci-base: prevent empty field for adding new entry 5154/head
authorHelge Mader <ma@dev.tdt.de>
Fri, 12 Mar 2021 09:48:29 +0000 (10:48 +0100)
committerFlorian Eckert <fe@dev.tdt.de>
Wed, 11 Aug 2021 06:48:41 +0000 (08:48 +0200)
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
modules/luci-base/htdocs/luci-static/resources/cbi.js
modules/luci-compat/luasrc/view/cbi/tblsection.htm
modules/luci-compat/luasrc/view/cbi/tsection.htm

index b66fe684a5d16eea48403ee006d6473054f55754..d6020e9d58fec728b0f0b0231d5c278aaef02513 100644 (file)
@@ -367,6 +367,17 @@ function cbi_validate_form(form, errmsg)
        return true;
 }
 
+function cbi_validate_named_section_add(input)
+{
+       var button = input.parentNode.parentNode.querySelector('.cbi-button-add');
+       if (input.value !== '') {
+               button.disabled = false;
+       }
+       else {
+               button.disabled = true;
+       }
+}
+
 function cbi_validate_reset(form)
 {
        window.setTimeout(
index 048eb22c417539e9209166c5ffca132e56e688b5..1cba66088473cc2beaf710253337f804a48c1215 100644 (file)
@@ -192,9 +192,9 @@ end
                                        <div class="cbi-section-error"><%:Invalid%></div>
                                <%- end %>
                                <div>
-                                       <input type="text" class="cbi-section-create-name" id="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" data-type="uciname" data-optional="true" />
+                                       <input type="text" class="cbi-section-create-name" id="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" data-type="uciname" data-optional="true" onkeyup="cbi_validate_named_section_add(this)"/>
                                </div>
-                               <input class="btn cbi-button cbi-button-add" type="submit" onclick="this.form.cbi_state='add-section'; return true" value="<%:Add%>" title="<%:Add%>" />
+                               <input class="btn cbi-button cbi-button-add" type="submit" onclick="this.form.cbi_state='add-section'; return true" value="<%:Add%>" title="<%:Add%>" disabled="" />
                        <% end %>
                </div>
                <%- end %>
index 45e51cc69f7230ee2311f7fb63ea7e8c91a2220a..703e1ff3285364432bfadfc064d952d71b552547 100644 (file)
@@ -42,9 +42,9 @@
                                        <div class="cbi-section-error"><%:Invalid%></div>
                                <%- end %>
                                <div>
-                                       <input type="text" class="cbi-section-create-name" id="cbi.cts.<%=self.config%>.<%=self.sectiontype%>." name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>." data-type="uciname" data-optional="true" />
+                                       <input type="text" class="cbi-section-create-name" id="cbi.cts.<%=self.config%>.<%=self.sectiontype%>." name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>." data-type="uciname" data-optional="true" onkeyup="cbi_validate_named_section_add(this)"/>
                                </div>
-                               <input class="btn cbi-button cbi-button-add" type="submit" onclick="this.form.cbi_state='add-section'; return true" value="<%:Add%>" title="<%:Add%>" />
+                               <input class="btn cbi-button cbi-button-add" type="submit" onclick="this.form.cbi_state='add-section'; return true" value="<%:Add%>" title="<%:Add%>" disabled=""/>
                        <%- end %>
                </div>
                <%- end %>