diff options
Diffstat (limited to 'acf2')
-rw-r--r-- | acf2/model/field.lua | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/acf2/model/field.lua b/acf2/model/field.lua index 809fdc3..409c004 100644 --- a/acf2/model/field.lua +++ b/acf2/model/field.lua @@ -27,7 +27,8 @@ end function M.Member:auto_ui_name(name) if not name then return end - return (name:sub(1, 1):upper()..name:sub(2)):gsub('-', ' ') + local res = (name:sub(1, 1):upper()..name:sub(2)):gsub('-', ' ') + return res end function M.Member:meta(context) @@ -46,9 +47,11 @@ function M.Field:init(params) if self.editable == nil then self.editable = not self.compute end - if self.choice and not self.ui_choice then - self.ui_choice = util.map( - function(name) return self:auto_ui_name(name) end, + if self.choice then + self.choice = util.map( + function(ch) + return type(ch) == 'table' and ch or {ch, self:auto_ui_name(ch)} + end, self.choice ) end @@ -69,7 +72,6 @@ function M.Field:meta(context) res.default = self.default res.choice = self.choice res.widget = self.widget - res['ui-choice'] = self.ui_choice return res end @@ -94,7 +96,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( - self.choice, value + util.map(function(ch) return ch[1] end, self.choice), value ) then raise(context.path, 'Invalid value') end |