summaryrefslogtreecommitdiffstats
path: root/acf2/model/field.lua
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-11-25 15:37:44 +0200
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-11-25 15:37:59 +0200
commita03cf9336873f63a98d0049996465c26b40405b8 (patch)
tree02b82bc5f2ce5b68ffe66ac012e31c4b94fcc16d /acf2/model/field.lua
parent91fd2ad0f9fb9a0cb4482a6405c4475036c999b3 (diff)
downloadaconf-a03cf9336873f63a98d0049996465c26b40405b8.tar.bz2
aconf-a03cf9336873f63a98d0049996465c26b40405b8.tar.xz
convert field choices to objects to allow additional parameters
Diffstat (limited to 'acf2/model/field.lua')
-rw-r--r--acf2/model/field.lua16
1 files changed, 13 insertions, 3 deletions
diff --git a/acf2/model/field.lua b/acf2/model/field.lua
index 64c727b..0600080 100644
--- a/acf2/model/field.lua
+++ b/acf2/model/field.lua
@@ -59,8 +59,18 @@ function M.Field:init(params)
if self.choice then
self.choice = util.map(
- function(ch)
- return type(ch) == 'table' and ch or {ch, self:auto_ui_name(ch)}
+ function(choice)
+ if type(choice) ~= 'table' then
+ choice = {choice, self:auto_ui_name(choice)}
+ end
+ for i, k in ipairs{'value', 'ui-value'} do
+ if choice[i] then
+ assert(not choice[k])
+ choice[k] = choice[i]
+ choice[i] = nil
+ end
+ end
+ return choice
end,
self.choice
)
@@ -106,7 +116,7 @@ function M.Field:_validate(context, value)
raise(context.path, 'Required value not set')
end
if self.choice and value ~= nil and not util.contains(
- util.map(function(ch) return ch[1] end, self.choice), value
+ util.map(function(ch) return ch.value end, self.choice), value
) then
raise(context.path, 'Invalid value')
end