Comparison

util/dataforms.lua @ 3380:e74e80b454a1

util.dataforms: Add list-multi support
author Florian Zeitz <florob@babelmonkeys.de>
date Thu, 15 Jul 2010 22:58:10 +0200
parent 3379:17d4298b2a58
child 3540:bc139431830b
comparison
equal deleted inserted replaced
3379:17d4298b2a58 3380:e74e80b454a1
77 end 77 end
78 else 78 else
79 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); 79 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up();
80 end 80 end
81 end 81 end
82 elseif field_type == "list-multi" then
83 for _, val in ipairs(value) do
84 if type(val) == "table" then
85 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up();
86 if val.default then
87 form:tag("value"):text(val.value):up();
88 end
89 else
90 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up();
91 end
92 end
82 end 93 end
83 end 94 end
84 95
85 if field.required then 96 if field.required then
86 form:tag("required"):up(); 97 form:tag("required"):up();
152 end 163 end
153 164
154 field_readers["list-single"] = 165 field_readers["list-single"] =
155 field_readers["text-single"]; 166 field_readers["text-single"];
156 167
168 field_readers["list-multi"] =
169 function (field_tag)
170 local result = {};
171 for value_tag in field_tag:childtags() do
172 if value_tag.name == "value" then
173 result[#result+1] = value_tag[1];
174 end
175 end
176 return result;
177 end
178
157 field_readers["boolean"] = 179 field_readers["boolean"] =
158 function (field_tag) 180 function (field_tag)
159 local value = field_tag:child_with_name("value"); 181 local value = field_tag:child_with_name("value");
160 if value then 182 if value then
161 if value[1] == "1" or value[1] == "true" then 183 if value[1] == "1" or value[1] == "true" then