Changeset

6981:bcaa553de6e8

util.dataforms: Track which fields are included in a form
author Kim Alvefur <zash@zash.se>
date Tue, 08 Dec 2015 20:16:49 +0100
parents 6980:daaa52b3f45f
children 6982:c515f9491ce6
files util/dataforms.lua
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/util/dataforms.lua	Tue Dec 08 20:12:38 2015 +0100
+++ b/util/dataforms.lua	Tue Dec 08 20:16:49 2015 +0100
@@ -118,6 +118,7 @@
 function form_t.data(layout, stanza)
 	local data = {};
 	local errors = {};
+	local present = {};
 
 	for _, field in ipairs(layout) do
 		local tag;
@@ -133,6 +134,7 @@
 				errors[field.name] = "Required value missing";
 			end
 		else
+			present[field.name] = true;
 			local reader = field_readers[field.type];
 			if reader then
 				data[field.name], errors[field.name] = reader(tag, field.required);
@@ -140,9 +142,9 @@
 		end
 	end
 	if next(errors) then
-		return data, errors;
+		return data, errors, present;
 	end
-	return data;
+	return data, nil, present;
 end
 
 local function simple_text(field_tag, required)