diff options
author | Kim Alvefur <zash@zash.se> | 2018-08-03 22:05:40 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2018-08-03 22:05:40 +0200 |
commit | 67ab854aac4c1cfec9e187d2a989b8c12f2c1547 (patch) | |
tree | 5357bafcfbe40f0459d83fb8291fe2c3330fb144 /util/dataforms.lua | |
parent | 724934bdc5962abf48b84d38f0b679330c5ea874 (diff) | |
download | prosody-67ab854aac4c1cfec9e187d2a989b8c12f2c1547.tar.gz prosody-67ab854aac4c1cfec9e187d2a989b8c12f2c1547.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.lua | 11 |
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 |