Changeset

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
parents 8983:23f66f04e216
children 8985:4101bcf9639a
files util/dataforms.lua
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/util/dataforms.lua	Fri Jul 06 19:02:19 2018 +0200
+++ b/util/dataforms.lua	Sat Jul 07 12:11:52 2018 +0100
@@ -42,9 +42,14 @@
 			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