Comparison

util/dataforms.lua @ 3379:17d4298b2a58

util.dataforms: Capability to set default for list-single
author Florian Zeitz <florob@babelmonkeys.de>
date Thu, 15 Jul 2010 21:31:57 +0200
parent 2923:b7049746bd29
child 3380:e74e80b454a1
comparison
equal deleted inserted replaced
3374:ce52f1d5cb74 3379:17d4298b2a58
65 -- Split into multiple <value> tags, one for each line 65 -- Split into multiple <value> tags, one for each line
66 for line in value:gmatch("([^\r\n]+)\r?\n*") do 66 for line in value:gmatch("([^\r\n]+)\r?\n*") do
67 form:tag("value"):text(line):up(); 67 form:tag("value"):text(line):up();
68 end 68 end
69 elseif field_type == "list-single" then 69 elseif field_type == "list-single" then
70 local has_default = false;
70 for _, val in ipairs(value) do 71 for _, val in ipairs(value) do
71 if type(val) == "table" then 72 if type(val) == "table" then
72 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); 73 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up();
74 if val.default and (not has_default) then
75 form:tag("value"):text(val.value):up();
76 has_default = true;
77 end
73 else 78 else
74 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();
75 end 80 end
76 end 81 end
77 end 82 end