diff options
Diffstat (limited to 'libs/cbi/luasrc')
-rw-r--r-- | libs/cbi/luasrc/cbi.lua | 20 | ||||
-rw-r--r-- | libs/cbi/luasrc/view/cbi/value.htm | 13 |
2 files changed, 23 insertions, 10 deletions
diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua index fe99f0246b..8c8f68b24a 100644 --- a/libs/cbi/luasrc/cbi.lua +++ b/libs/cbi/luasrc/cbi.lua @@ -595,7 +595,10 @@ function AbstractValue.render(self, s, scope) if cond then return string.format( ' %s="%s"', tostring(key), - tostring( val or scope[key] or self[key] or "" ) + tostring( val + or scope[key] + or (type(self[key]) ~= "function" and self[key]) + or "" ) ) else return '' @@ -642,17 +645,14 @@ Value = class(AbstractValue) function Value.__init__(self, ...) AbstractValue.__init__(self, ...) self.template = "cbi/value" - - self.maxlength = nil + self.keylist = {} + self.vallist = {} end --- This validation is a bit more complex -function Value.validate(self, val) - if self.maxlength and tostring(val):len() > self.maxlength then - val = nil - end - - return val +function Value.value(self, key, val) + val = val or key + table.insert(self.keylist, tostring(key)) + table.insert(self.vallist, tostring(val)) end diff --git a/libs/cbi/luasrc/view/cbi/value.htm b/libs/cbi/luasrc/view/cbi/value.htm index 5a7339d835..4d473bf5e6 100644 --- a/libs/cbi/luasrc/view/cbi/value.htm +++ b/libs/cbi/luasrc/view/cbi/value.htm @@ -14,4 +14,17 @@ $Id$ -%> <%+cbi/valueheader%> <input type="text" onchange="cbi_d_update(this.id)"<%= attr("name", cbid) .. attr("id", cbid) .. attr("value", self:cfgvalue(section)) .. ifattr(self.size, "size") .. ifattr(self.maxlength, "maxlength") %> /> + <% if #self.keylist > 0 then -%> + <script type="text/javascript"> + cbi_combobox_init('<%=cbid%>', { + <%- + for i, k in ipairs(self.keylist) do + -%> + <%-=string.format("%q", k) .. ":" .. string.format("%q", self.vallist[i])-%>, + <%- + end + -%> + }, '<%:cbi_select%>', '<%:cbi_manual%>'); + </script> + <% end -%> <%+cbi/valuefooter%> |