luci-base: fix dependency handling of optionals (#645)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
parent
84de513a79
commit
cd85ef388c
2 changed files with 8 additions and 18 deletions
|
@ -490,6 +490,10 @@ function cbi_d_update() {
|
|||
|
||||
state = true;
|
||||
}
|
||||
|
||||
// hide optionals widget if no choices remaining
|
||||
if (parent.parentNode && parent.getAttribute('data-optionals'))
|
||||
parent.parentNode.style.display = (parent.options.length <= 1) ? 'none' : '';
|
||||
}
|
||||
|
||||
if (entry && entry.parent) {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<% end %>
|
||||
|
||||
<% if self.error and self.error[section] then -%>
|
||||
<div class="cbi-section-error">
|
||||
<div class="cbi-section-error" data-index="<%=#self.children + 1%>">
|
||||
<ul><% for _, e in ipairs(self.error[section]) do -%>
|
||||
<li>
|
||||
<%- if e == "invalid" then -%>
|
||||
|
@ -31,7 +31,7 @@
|
|||
<%- end %>
|
||||
|
||||
<% if self.optionals[section] and #self.optionals[section] > 0 or self.dynamic then %>
|
||||
<div class="cbi-optionals">
|
||||
<div class="cbi-optionals" data-index="<%=#self.children + 1%>">
|
||||
<% if self.dynamic then %>
|
||||
<input type="text" id="cbi.opt.<%=self.config%>.<%=section%>" name="cbi.opt.<%=self.config%>.<%=section%>" />
|
||||
<% if self.optionals[section] and #self.optionals[section] > 0 then %>
|
||||
|
@ -49,26 +49,12 @@
|
|||
</script>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<select id="cbi.opt.<%=self.config%>.<%=section%>" name="cbi.opt.<%=self.config%>.<%=section%>">
|
||||
<select id="cbi.opt.<%=self.config%>.<%=section%>" name="cbi.opt.<%=self.config%>.<%=section%>" data-optionals="true">
|
||||
<option><%: -- Additional Field -- %></option>
|
||||
<% for key, val in pairs(self.optionals[section]) do -%>
|
||||
<option id="cbi-<%=self.config.."-"..section.."-"..val.option%>" value="<%=val.option%>"><%=striptags(val.title)%></option>
|
||||
<option id="cbi-<%=self.config.."-"..section.."-"..val.option%>" value="<%=val.option%>" data-index="<%=val.index%>" data-depends="<%=pcdata(val:deplist2json(section))%>"><%=striptags(val.title)%></option>
|
||||
<%- end %>
|
||||
</select>
|
||||
<script type="text/javascript"><% for key, val in pairs(self.optionals[section]) do %>
|
||||
<% if #val.deps > 0 then %><% for j, d in ipairs(val.deps) do -%>
|
||||
cbi_d_add("cbi-<%=self.config.."-"..section.."-"..val.option..d.add%>", {
|
||||
<%-
|
||||
for k,v in pairs(d.deps) do
|
||||
-%>
|
||||
<%-=string.format('"cbid.%s.%s.%s"', self.config, section, k) .. ":" .. string.format("%q", v)-%>
|
||||
<%-if next(d.deps, k) then-%>,<%-end-%>
|
||||
<%-
|
||||
end
|
||||
-%>
|
||||
});
|
||||
<%- end %><% end %>
|
||||
<% end %></script>
|
||||
<% end %>
|
||||
<input type="submit" class="cbi-button cbi-button-fieldadd" value="<%:Add%>" />
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue