libs/web: rework DynamicList widget
[project/luci.git] / libs / web / luasrc / view / cbi / dynlist.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008-2010 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 -%>
15 <%+cbi/valueheader%>
16 <div>
17 <%
18         local vals = self:cfgvalue(section) or {}
19         for i=1, #vals + 1 do
20                 local val = vals[i]
21 %>
22         <input class="cbi-input-text" value="<%=pcdata(val)%>" onchange="cbi_d_update(this.id)" type="text"<%= attr("id", cbid .. "." .. i) .. attr("name", cbid) .. ifattr(self.size, "size")%> /><br />
23 <% end %>
24 </div>
25 <script type="text/javascript">
26 cbi_dynlist_init('<%=cbid%>');
27 <% if self.datatype then -%>
28         <% if #self.keylist > 0 then -%>
29                 cbi_combobox_init('<%=cbid .. "." .. i%>', {
30                 <%- for i, k in ipairs(self.keylist) do -%>
31                         <%-=string.format("%q", k) .. ":" .. string.format("%q", self.vallist[i])-%>
32                         <%-if i<#self.keylist then-%>,<%-end-%>
33                 <%-     end     -%>
34                 }, '<%- if not self.rmempty and not self.optional then -%>
35                         <%-:cbi_select-%>
36                 <%- end -%>', '<%: -- custom -- %>');
37         <% end -%>
38         <% for i=1, #vals + 1 do -%>
39         cbi_validate_field('<%=cbid%>.<%=i%>', <%=tostring(self.optional == true or i > #vals)%>, '<%=self.datatype%>');
40         <%- end %>
41 <% end -%>
42 </script>
43 <%+cbi/valuefooter%>