Software /
code /
prosody
Changeset
3381:28cb5ad72870
Merge Florob->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 16 Jul 2010 16:53:54 +0100 |
parents | 3378:bb49ada7cf45 (current diff) 3380:e74e80b454a1 (diff) |
children | 3382:fea0f8e19e4c |
files | |
diffstat | 1 files changed, 27 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/util/dataforms.lua Fri Jul 16 15:19:44 2010 +0100 +++ b/util/dataforms.lua Fri Jul 16 16:53:54 2010 +0100 @@ -67,9 +67,25 @@ form:tag("value"):text(line):up(); end elseif field_type == "list-single" then + local has_default = false; 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 val.default and (not has_default) then + form:tag("value"):text(val.value):up(); + has_default = true; + end + else + form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); + end + end + elseif field_type == "list-multi" 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 val.default then + form:tag("value"):text(val.value):up(); + end else form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); end @@ -149,6 +165,17 @@ field_readers["list-single"] = field_readers["text-single"]; +field_readers["list-multi"] = + function (field_tag) + local result = {}; + for value_tag in field_tag:childtags() do + if value_tag.name == "value" then + result[#result+1] = value_tag[1]; + end + end + return result; + end + field_readers["boolean"] = function (field_tag) local value = field_tag:child_with_name("value");