summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--acf2/model/field.lua16
-rw-r--r--protocol.txt6
-rw-r--r--web/client.js8
3 files changed, 23 insertions, 7 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
diff --git a/protocol.txt b/protocol.txt
index f0ad9cb..68f62d7 100644
--- a/protocol.txt
+++ b/protocol.txt
@@ -62,8 +62,10 @@ resp: JSON object, with the following attributes:
- required (boolean)
- default
- max-length
- - choices (optional array of allowed values, which are
- tuples of actual values and user-friendly versions)
+ - choices: optional array of allowed values, which are
+ objects with the following attributes:
+ - value
+ - ui-value (user-friendly version)
- fields (model only): array of field metadata JSON
objects
- members (collections and sets only): metadata for
diff --git a/web/client.js b/web/client.js
index 38c8515..cf7910f 100644
--- a/web/client.js
+++ b/web/client.js
@@ -585,7 +585,11 @@ $(function() {
_.each(
meta.choice,
function(choice) {
- opt(choice[0], choice[1], value == choice[0]);
+ opt(
+ choice.value,
+ choice["ui-value"],
+ value == choice.value
+ );
}
);
}
@@ -1009,7 +1013,7 @@ $(function() {
var def = $.Deferred();
txnMgr.query(meta.scope).done(function(data) {
meta.choice = _.map(_.values(data.data), function(path) {
- return [path, split(path).pop()];
+ return {value: path, "ui-value": split(path).pop()};
});
def.resolve(value, meta);
});