Changeset

1958:e2b0026143c4

util.dataforms: Incorporate slightly modified patch for list-single type from Florob
author Matthew Wild <mwild1@gmail.com>
date Fri, 16 Oct 2009 19:52:09 +0100
parents 1957:5856b2dcf81e
children 1959:f56670ce64de
files util/dataforms.lua
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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");