Software /
code /
prosody
Comparison
util/dataforms.lua @ 9091:519dea077d20
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
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 03 Aug 2018 22:05:40 +0200 |
parent | 9090:56c52cb4d44e |
child | 9092:5110da3a71eb |
comparison
equal
deleted
inserted
replaced
9090:56c52cb4d44e | 9091:519dea077d20 |
---|---|
55 value = data[field.name]; | 55 value = data[field.name]; |
56 else | 56 else |
57 value = field.value; | 57 value = field.value; |
58 end | 58 end |
59 | 59 |
60 if formtype == "form" and field.options then | 60 local options = field.options; |
61 if formtype == "form" and not options and value | |
62 and (field_type == "list-single" or field_type == "list-multi") then | |
63 -- Allow passing dynamically generated options as values | |
64 options, value = value, nil; | |
65 end | |
66 | |
67 if formtype == "form" and options then | |
61 local defaults = {}; | 68 local defaults = {}; |
62 for _, val in ipairs(field.options) do | 69 for _, val in ipairs(options) do |
63 if type(val) == "table" then | 70 if type(val) == "table" then |
64 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); | 71 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); |
65 if val.default then | 72 if val.default then |
66 defaults[#defaults+1] = val.value; | 73 defaults[#defaults+1] = val.value; |
67 end | 74 end |