libs/web: skip empty values in DynList widget
authorJo-Philipp Wich <jow@openwrt.org>
Sat, 20 Nov 2010 18:08:18 +0000 (18:08 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sat, 20 Nov 2010 18:08:18 +0000 (18:08 +0000)
libs/web/luasrc/cbi.lua
libs/web/luasrc/view/cbi/dynlist.htm

index 6c9e7a544f2d2cad8ee5721dc6ff65032570693e..50b594b4ce911fb309738b689e0e3a96522c29b0 100644 (file)
@@ -1662,7 +1662,9 @@ function DynamicList.write(self, section, value)
        elseif self.cast == "table" and type(value) == "string" then
                local x, t = { }
                for x in value:gmatch("%S+") do
-                       t[#t+1] = x
+                       if #x > 0 then
+                               t[#t+1] = x
+                       end
                end
                value = t
        end
@@ -1677,7 +1679,9 @@ function DynamicList.cfgvalue(self, section)
                local x
                local t = { }
                for x in value:gmatch("%S+") do
-                       t[#t+1] = x
+                       if #x > 0 then
+                               t[#t+1] = x
+                       end
                end
                value = t
        end
index 5f57941b800072c57bf4ac52ccdfa68c0f18b1a4..90f3f1e90575cb30e9318c0af769929ec23680ff 100644 (file)
@@ -18,12 +18,13 @@ $Id$
        local vals = self:cfgvalue(section) or {}
        for i=1, #vals + 1 do
                local val = vals[i]
+               if val and #val > 0 then
 %>
        <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") ..
                ifattr(i == 1 and self.placeholder, "placeholder", self.placeholder)
        %> /><br />
-<% end %>
+<% end end %>
 </div>
 <script type="text/javascript">
 cbi_dynlist_init('<%=cbid%>');