[luci] how to transform multi input to one uci cfgvalue

Michael Fung mike at cmsweb.com
Mon Mar 2 02:14:15 CET 2009


Hello Steven,

Thank you so much. It works! Except I need to change to 
match("(%d%d):%d%d")  and so on.

Rgds,
Michael

----- Original Message ----- 
From: "Steven Barth" <steven at midlink.org>
To: <luci at lists.subsignal.org>; "Michael Fung" <mike at cmsweb.com>
Sent: Saturday, 28 February, 2009 7:35 PM
Subject: Re: [luci] how to transform multi input to one uci cfgvalue


> 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