diff options
author | Matthew Wild <mwild1@gmail.com> | 2010-07-16 16:53:54 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2010-07-16 16:53:54 +0100 |
commit | dd08ddb30b0dff37bfda45bc408d7e9c4c670ea8 (patch) | |
tree | 97c6568f01a72ab9863ecec04fdf705134c98ef4 | |
parent | 7abdf45d82c4805df039dc052d52814f0ae06345 (diff) | |
parent | 1f7f8e57a3f5bbffdc261285c8ef46e9749e22d3 (diff) | |
download | prosody-dd08ddb30b0dff37bfda45bc408d7e9c4c670ea8.tar.gz prosody-dd08ddb30b0dff37bfda45bc408d7e9c4c670ea8.zip |
Merge Florob->trunk
-rw-r--r-- | util/dataforms.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/util/dataforms.lua b/util/dataforms.lua index 5a3b1fb5..7814ada0 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -67,9 +67,25 @@ function form_t.form(layout, data, formtype) 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["text-multi"] = 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"); |