luci-base: fix field section add button/input field names

Some CBI map models, mainly the Network -> VLAN page, expect a valid
previous section ID in their Section:create() callback.

Previous refactoring of the tblsection markup broke this behaviour as
the "section" loop variable was accidentally localized, causing it to
be undefined outside of the loop body which caused the section add
button and name input fields to get rendered with a wrong "name"
attribute.

Fix this by moving the "section" variable declaration out of the loop
and by readding references to it in the non-anonymous section add case.

Fixes FS#1657
Fixes 002c4d1d5 ("luci-base: add "Name" label to autogenerated title column")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>

(cherry picked from commit fcc9cd6a9a)
This commit is contained in:
Jo-Philipp Wich 2018-07-16 17:28:50 +02:00
parent 911219898f
commit 4da137e892

View file

@ -55,11 +55,11 @@ local titlename = ifattr(not self.anonymous or self.sectiontitle, "data-title",
<div class="th cbi-section-table-cell cbi-section-actions"></div> <div class="th cbi-section-table-cell cbi-section-actions"></div>
<%- end -%> <%- end -%>
</div> </div>
<%- local isempty, i, k = true, nil, nil <%- local isempty, section, i, k = true, nil, nil
for i, k in ipairs(self:cfgsections()) do for i, k in ipairs(self:cfgsections()) do
isempty = false isempty = false
section = k
local section = k
local sectionname = striptags((type(self.sectiontitle) == "function") and self:sectiontitle(section) or k) local sectionname = striptags((type(self.sectiontitle) == "function") and self:sectiontitle(section) or k)
local sectiontitle = ifattr(sectionname and (not self.anonymous or self.sectiontitle), "data-title", sectionname) local sectiontitle = ifattr(sectionname and (not self.anonymous or self.sectiontitle), "data-title", sectionname)
local colorclass = (self.extedit or self.rowcolors) and " cbi-rowstyle-%d" % rowstyle() or "" local colorclass = (self.extedit or self.rowcolors) and " cbi-rowstyle-%d" % rowstyle() or ""
@ -126,7 +126,7 @@ local titlename = ifattr(not self.anonymous or self.sectiontitle, "data-title",
<div class="cbi-section-error"><%:Invalid%></div> <div class="cbi-section-error"><%:Invalid%></div>
<%- end %> <%- end %>
<div> <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%>.<%=section%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" data-type="uciname" data-optional="true" />
</div> </div>
<input class="cbi-button cbi-button-add" type="submit" onclick="this.form.cbi_state='add-section'; return true" value="<%:Add%>" title="<%:Add%>" /> <input class="cbi-button cbi-button-add" type="submit" onclick="this.form.cbi_state='add-section'; return true" value="<%:Add%>" title="<%:Add%>" />
<% end %> <% end %>