summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2016-02-09 16:10:55 +0100
committerJo-Philipp Wich <jow@openwrt.org>2016-02-09 16:12:02 +0100
commitcd85ef388cfb9134e3de490ff5d395f593783f8c (patch)
tree1722d7ddd880dcfd3a461cdae09f1e2f1f3391dd /modules/luci-base
parent84de513a79c1714ffa8e51009b7aa97ef975961d (diff)
luci-base: fix dependency handling of optionals (#645)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'modules/luci-base')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/cbi.js4
-rw-r--r--modules/luci-base/luasrc/view/cbi/ucisection.htm22
2 files changed, 8 insertions, 18 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js
index 227461070..a8d323d6a 100644
--- a/modules/luci-base/htdocs/luci-static/resources/cbi.js
+++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js
@@ -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) {
diff --git a/modules/luci-base/luasrc/view/cbi/ucisection.htm b/modules/luci-base/luasrc/view/cbi/ucisection.htm
index 3b69f12f2..ba0cc53e8 100644
--- a/modules/luci-base/luasrc/view/cbi/ucisection.htm
+++ b/modules/luci-base/luasrc/view/cbi/ucisection.htm
@@ -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>