aboutsummaryrefslogtreecommitdiffstats
path: root/util/dataforms.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-10-26 15:15:57 +0200
committerKim Alvefur <zash@zash.se>2021-10-26 15:15:57 +0200
commitfc677f515fd0fe5c45d54e51f5646f37e204929a (patch)
treec02eafc57e427c68964ea99d0ac24736a0c490a7 /util/dataforms.lua
parent533ab7a4ce6c55acd164cdcea6d8a6abe3db4bca (diff)
downloadprosody-fc677f515fd0fe5c45d54e51f5646f37e204929a.tar.gz
prosody-fc677f515fd0fe5c45d54e51f5646f37e204929a.zip
util.dataforms: Coerce number values for boolean fields
Makes more sense than coercing to a string, which would always be truthy.
Diffstat (limited to 'util/dataforms.lua')
-rw-r--r--util/dataforms.lua7
1 files changed, 5 insertions, 2 deletions
diff --git a/util/dataforms.lua b/util/dataforms.lua
index 79559b22..7bb3cff9 100644
--- a/util/dataforms.lua
+++ b/util/dataforms.lua
@@ -103,8 +103,11 @@ function form_t.form(layout, data, formtype)
if value ~= nil then
if type(value) == "number" then
- -- TODO validate that this is ok somehow, eg check field.datatype
- value = ("%g"):format(value);
+ if field_type == "boolean" then
+ value = value ~= 0;
+ else
+ value = ("%g"):format(value);
+ end
end
-- Add value, depending on type
if field_type == "hidden" then