util.dataforms: Incorporate slightly modified patch for list-single type from Florob

Fri, 16 Oct 2009 19:52:09 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 16 Oct 2009 19:52:09 +0100
changeset 1958
e2b0026143c4
parent 1957
5856b2dcf81e
child 1959
f56670ce64de

util.dataforms: Incorporate slightly modified patch for list-single type from Florob

util/dataforms.lua file | annotate | diff | comparison | revisions
--- a/util/dataforms.lua	Fri Oct 16 00:11:55 2009 +0100
+++ b/util/dataforms.lua	Fri Oct 16 19:52:09 2009 +0100
@@ -10,7 +10,6 @@
 local pairs, ipairs = pairs, ipairs;
 local tostring, type = tostring, type;
 local t_concat = table.concat;
-
 local st = require "util.stanza";
 
 module "dataforms"
@@ -66,6 +65,14 @@
 			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
 		
 		if field.required then
@@ -120,6 +127,9 @@
 		return t_concat(result, "\n");
 	end
 
+field_readers["list-single"] =
+	field_readers["text-single"];
+
 field_readers["boolean"] = 
 	function (field_tag)
 		local value = field_tag:child_with_name("value");

mercurial