[luci] how to transform multi input to one uci cfgvalue
Steven Barth
steven at midlink.org
Sat Feb 28 12:35:47 CET 2009
Hi,
please try this:
1. Create a new view e.g. luasrc/view/cbi_timeval.htm like this
<%+cbi/valueheader%>
<input type="text" class="cbi-input-text" onchange="cbi_d_update(this.id)"<%=
attr("name", cbid .. ".hour") .. attr("id", cbid ..".hour") .. attr("value",
(self:cfgvalue(section) or ""):match("(.*):?.*")) %> />
:
<input type="text" class="cbi-input-text" onchange="cbi_d_update(this.id)"<%=
attr("name", cbid .. ".min") .. attr("id", cbid ..".min") .. attr("value",
(self:cfgvalue(section) or ""):match(".*:?(.*)")) %> />
<%+cbi/valuefooter%>
Important are the includes at the beggining and the end, and that the id, name
and value attributes are correct. The rest can be adapted.
(self:cfgvalue(section) or ""):match(".*:?(.*)") will only match the part of
the configvalue behind the : whereas (self:cfgvalue(section) or
""):match("(.*):?.*") will only match the first part of the real config value.
2. In your Model do something like this.
somename = s:option(Value, "option", "name") -- or whatever creating a Value
somename.template = "cbi_timeval" -- Template name from above
somename.formvalue = function(self, section) -- This will assemble the parts
local hour = self.map:formvalue(self:cbid(section) .. ".hour")
local min = self.map:formvalue(self:cbid(section) .. ".min")
if hour and min and #hour > 0 and #min > 0 then
return hour .. ":" .. min
else
return nil
end
end
That should be enough. This is a quick solution that just came to my mind, I
think it should work.
Have a nice day.
Steven
More information about the luci
mailing list