util.dataforms: Incorporate slightly modified patch for list-single type from Florob
authorMatthew Wild <mwild1@gmail.com>
Fri, 16 Oct 2009 18:52:09 +0000 (19:52 +0100)
committerMatthew Wild <mwild1@gmail.com>
Fri, 16 Oct 2009 18:52:09 +0000 (19:52 +0100)
util/dataforms.lua

index b9fd23f2e2a0781104b969cfeb609815764f268b..46e22dc1516fbe75792efc8f2b4aed2935f70816 100644 (file)
@@ -10,7 +10,6 @@ local setmetatable = setmetatable;
 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 @@ function form_t.form(layout, data)
                        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 @@ field_readers["text-multi"] =
                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");