[luci] Help validating a DynamicList
Chris Martin
chris at martin.cc
Fri Sep 17 07:10:57 CEST 2010
I have the following code to validate each of the values of a dynamic list.
It works OK however I have the following issues that I am unsure how to
resolve
(1) when nil is returned the the "new" invalid entry is lost
(2) when nil is returned ALL the valid entries are highlighted.
Ideally I would like to have only the invalid entry highlighted and have it
displaying the invalid value
Does anyone know of a way to do this?
Thanks
mr = s:option(DynamicList, "mac_addr_range", "Voice MAC Addresses ")
mr.description="Devices matching these MAC addresses will be allocated to
the Voice VLAN. Traffic from all other wireless devices will be allocated to
the Data VLAN"
function mr.validate(self, value)
for i, v in ipairs(value) do
-- trim white space
v = v:gsub("%s", "")
value[i] = v
-- now check the format
if not (
v:match("^%x%x?:%x%x?:%x%x?:%x%x?:%x%x?:%x%x?%-%x%x?:%x%x?:%x%x?:%x%x?:%x%x?:%x%x?$")
or
v:match("^%x%x?:%x%x?:%x%x?:%x%x?:%x%x?:%x%x?$") or
v:match("^%x%x?:%x%x?:%x%x?:%x%x?:%x%x?:%*$") or
v:match("^%x%x?:%x%x?:%x%x?:%x%x?:%*$") or
v:match("^%x%x?:%x%x?:%x%x?:%*$") or
v:match("^%x%x?:%x%x?:%*$") or
v:match("^%x%x?:%*$") ) then
return nil
end
end
return value
end
----------------------------------------------------------
Chris Martin
m: 0419812371
----------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.subsignal.org/pipermail/luci/attachments/20100917/72291f07/attachment.htm
More information about the luci
mailing list