diff options
author | Matthew Wild <mwild1@gmail.com> | 2018-07-07 12:11:52 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2018-07-07 12:11:52 +0100 |
commit | bdb4a84ec419346ccede674299caa23ce51abff6 (patch) | |
tree | 1118a7795fbc821dabb5995c1ffc9a093c98859b | |
parent | 24ff76428fed35700c9e10c127920f201c6c6b13 (diff) | |
download | prosody-bdb4a84ec419346ccede674299caa23ce51abff6.tar.gz prosody-bdb4a84ec419346ccede674299caa23ce51abff6.zip |
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.
-rw-r--r-- | util/dataforms.lua | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/util/dataforms.lua b/util/dataforms.lua index e48f6879..64f73c11 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -42,9 +42,14 @@ function form_t.form(layout, data, formtype) form:text_tag("desc", field.desc); end - local value = (data and data[field.name]) or field.value; + local value; + if data and data[field.name] ~= nil then + value = data[field.name]; + else + value = field.value; + end - if value then + if value ~= nil then -- Add value, depending on type if field_type == "hidden" then if type(value) == "table" then |