luci-base: fix dependency handling of optionals (#645)
[project/luci.git] / modules / luci-base / luasrc / view / cbi / ucisection.htm
index 3b69f12..ba0cc53 100644 (file)
@@ -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 %>
                        </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>