[luci] Please help with validating unique vlaues
Jo-Philipp Wich
xm at subsignal.org
Mon Feb 22 14:59:46 CET 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi.
> I have a requirement to validate some input data to make sure that it
> is unique, unfortunately I don't seem to be able to see a way forward.
You can define a validate function for a whole section, this allows you
to validate all fields within it. It gets self and the section id as
parameters.
The fields are stored in a key->value table within self.fields, you can
access their :formvalue() member function to obtain the values you want.
Try something like that:
m = Map(...)
s = m:section(...)
function s.validate(self, sectionid)
local field, obj
local values = { }
for field, obj in pairs(self.fields) do
local fieldval = obj:formvalue(sectionid)
if not values[fieldval] then
values[fieldval] = true
else
return nil -- raise error
end
end
return sectionid -- signalize success
end
~ JoW
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkuCjc8ACgkQdputYINPTPNYngCeMwSSZc5eB5ObDGg65eQeX5tC
frEAnjU4yqp8S/VgIOHIMoWl5gX2LXlK
=epi4
-----END PGP SIGNATURE-----
More information about the luci
mailing list