aboutsummaryrefslogtreecommitdiffstats
path: root/util/dataforms.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-08-03 22:05:40 +0200
committerKim Alvefur <zash@zash.se>2018-08-03 22:05:40 +0200
commit414778ee5d861e9e23dd54a690cc341ba98b658c (patch)
tree5357bafcfbe40f0459d83fb8291fe2c3330fb144 /util/dataforms.lua
parent383dc3fbfd49e6a86dd1a2b51bf49ecaa063a47b (diff)
downloadprosody-414778ee5d861e9e23dd54a690cc341ba98b658c.tar.gz
prosody-414778ee5d861e9e23dd54a690cc341ba98b658c.zip
util.dataforms: Allow passing dynamically generated options as values (fixes traceback)
This is awkward but there’s currently no better way to do this, short of dynamically generating the entire form each time
Diffstat (limited to 'util/dataforms.lua')
-rw-r--r--util/dataforms.lua11
1 files changed, 9 insertions, 2 deletions
diff --git a/util/dataforms.lua b/util/dataforms.lua
index 649676f8..45f1a79a 100644
--- a/util/dataforms.lua
+++ b/util/dataforms.lua
@@ -57,9 +57,16 @@ function form_t.form(layout, data, formtype)
value = field.value;
end
- if formtype == "form" and field.options then
+ local options = field.options;
+ if formtype == "form" and not options and value
+ and (field_type == "list-single" or field_type == "list-multi") then
+ -- Allow passing dynamically generated options as values
+ options, value = value, nil;
+ end
+
+ if formtype == "form" and options then
local defaults = {};
- for _, val in ipairs(field.options) do
+ for _, val in ipairs(options) do
if type(val) == "table" then
form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up();
if val.default then