Comparison

util/dataforms.lua @ 9094:05979ae1e38a

util.dataforms: Only allow overriding of options when passed via the :form method
author Kim Alvefur <zash@zash.se>
date Fri, 03 Aug 2018 22:55:28 +0200
parent 9092:5110da3a71eb
child 9111:bc7473fb7ad3
comparison
equal deleted inserted replaced
9093:04a284c5b88b 9094:05979ae1e38a
48 if field.desc then 48 if field.desc then
49 form:text_tag("desc", field.desc); 49 form:text_tag("desc", field.desc);
50 end 50 end
51 end 51 end
52 52
53 local value; 53 local value = field.value;
54 local options = field.options;
55
54 if data and data[field.name] ~= nil then 56 if data and data[field.name] ~= nil then
55 value = data[field.name]; 57 value = data[field.name];
56 else 58
57 value = field.value; 59 if formtype == "form" and type(value) == "table"
58 end 60 and (field_type == "list-single" or field_type == "list-multi") then
59 61 -- Allow passing dynamically generated options as values
60 local options = field.options; 62 options, value = value, nil;
61 if formtype == "form" and value 63 end
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 64 end
66 65
67 if formtype == "form" and options then 66 if formtype == "form" and options then
68 local defaults = {}; 67 local defaults = {};
69 for _, val in ipairs(options) do 68 for _, val in ipairs(options) do