From 2b25602115bfc936f7d4646c50613df768177388 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Fri, 30 Oct 2009 01:18:56 +0000 Subject: util.dataforms: Only add value to rendered form if supplied in the data --- util/dataforms.lua | 66 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/util/dataforms.lua b/util/dataforms.lua index 46e22dc1..f71ceb46 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -38,39 +38,41 @@ function form_t.form(layout, data) 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 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 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 -- cgit v1.2.3