Comparison

util/dataforms.lua @ 11877:593b141ba01c

util.dataforms: Coerce number values for boolean fields Makes more sense than coercing to a string, which would always be truthy.
author Kim Alvefur <zash@zash.se>
date Tue, 26 Oct 2021 15:15:57 +0200
parent 11874:84f4c6957d62
child 11878:bf6706057283
comparison
equal deleted inserted replaced
11876:52a1b885044e 11877:593b141ba01c
101 end 101 end
102 end 102 end
103 103
104 if value ~= nil then 104 if value ~= nil then
105 if type(value) == "number" then 105 if type(value) == "number" then
106 -- TODO validate that this is ok somehow, eg check field.datatype 106 if field_type == "boolean" then
107 value = ("%g"):format(value); 107 value = value ~= 0;
108 else
109 value = ("%g"):format(value);
110 end
108 end 111 end
109 -- Add value, depending on type 112 -- Add value, depending on type
110 if field_type == "hidden" then 113 if field_type == "hidden" then
111 if type(value) == "table" then 114 if type(value) == "table" then
112 -- Assume an XML snippet 115 -- Assume an XML snippet