Changeset

2061:e34fdca432a9

util.dataforms: Only add value to rendered form if supplied in the data
author Florian Zeitz
date Fri, 30 Oct 2009 01:18:56 +0000
parents 2060:b23295b5428a
children 2062:699686c8d016
files util/dataforms.lua
diffstat 1 files changed, 34 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/util/dataforms.lua	Fri Oct 30 01:18:38 2009 +0000
+++ b/util/dataforms.lua	Fri Oct 30 01:18:56 2009 +0000
@@ -38,39 +38,41 @@
 
 		local value = (data and data[field.name]) or field.value;
 		
-		-- Add value, depending on type
-		if field_type == "hidden" then
-			if type(value) == "table" then
-				-- Assume an XML snippet
-				form:tag("value")
-					:add_child(value)
-					:up();
-			elseif value then
-				form:tag("value"):text(tostring(value)):up();
-			end
-		elseif field_type == "boolean" then
-			form:tag("value"):text((value and "1") or "0"):up();
-		elseif field_type == "fixed" then
-			
-		elseif field_type == "jid-multi" then
-			for _, jid in ipairs(value) do
-				form:tag("value"):text(jid):up();
-			end
-		elseif field_type == "jid-single" then
-			form:tag("value"):text(value):up();
-		elseif field_type == "text-single" or field_type == "text-private" then
-			form:tag("value"):text(value):up();
-		elseif field_type == "text-multi" then
-			-- Split into multiple <value> tags, one for each line
-			for line in value:gmatch("([^\r\n]+)\r?\n*") do
-				form:tag("value"):text(line):up();
-			end
-		elseif field_type == "list-single" then
-			for _, val in ipairs(value) do
-				if type(val) == "table" then
-					form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up();
+		if value then
+			-- Add value, depending on type
+			if field_type == "hidden" then
+				if type(value) == "table" then
+					-- Assume an XML snippet
+					form:tag("value")
+						:add_child(value)
+						:up();
 				else
-					form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up();
+					form:tag("value"):text(tostring(value)):up();
+				end
+			elseif field_type == "boolean" then
+				form:tag("value"):text((value and "1") or "0"):up();
+			elseif field_type == "fixed" then
+				
+			elseif field_type == "jid-multi" then
+				for _, jid in ipairs(value) do
+					form:tag("value"):text(jid):up();
+				end
+			elseif field_type == "jid-single" then
+				form:tag("value"):text(value):up();
+			elseif field_type == "text-single" or field_type == "text-private" then
+				form:tag("value"):text(value):up();
+			elseif field_type == "text-multi" then
+				-- Split into multiple <value> tags, one for each line
+				for line in value:gmatch("([^\r\n]+)\r?\n*") do
+					form:tag("value"):text(line):up();
+				end
+			elseif field_type == "list-single" then
+				for _, val in ipairs(value) do
+					if type(val) == "table" then
+						form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up();
+					else
+						form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up();
+					end
 				end
 			end
 		end