Software /
code /
prosody
Comparison
util/dataforms.lua @ 8984:fa80b3231a02
util.dataforms: More robust handling of field values, especially booleans
Ensure that a non-nil data[field_name] always overrides the field's default,
and that values of boolean 'false' are always rendered in the form.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 07 Jul 2018 12:11:52 +0100 |
parent | 8945:cbeb1a045eb6 |
child | 9047:ab3488ee3ca5 |
comparison
equal
deleted
inserted
replaced
8983:23f66f04e216 | 8984:fa80b3231a02 |
---|---|
40 | 40 |
41 if field.desc then | 41 if field.desc then |
42 form:text_tag("desc", field.desc); | 42 form:text_tag("desc", field.desc); |
43 end | 43 end |
44 | 44 |
45 local value = (data and data[field.name]) or field.value; | 45 local value; |
46 | 46 if data and data[field.name] ~= nil then |
47 if value then | 47 value = data[field.name]; |
48 else | |
49 value = field.value; | |
50 end | |
51 | |
52 if value ~= nil then | |
48 -- Add value, depending on type | 53 -- Add value, depending on type |
49 if field_type == "hidden" then | 54 if field_type == "hidden" then |
50 if type(value) == "table" then | 55 if type(value) == "table" then |
51 -- Assume an XML snippet | 56 -- Assume an XML snippet |
52 form:tag("value") | 57 form:tag("value") |