Software / code / prosody
Comparison
util/dataforms.lua @ 8255:d70d4c1ac17a
util.dataforms: Don't include list options in result forms (fixes #983)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 23 Sep 2017 13:20:46 +0100 |
| parent | 7446:0db72fac2faa |
| child | 8555:4f0f5b49bb03 |
comparison
equal
deleted
inserted
replaced
| 8254:e3f7b6fa46ba | 8255:d70d4c1ac17a |
|---|---|
| 66 -- Split into multiple <value> tags, one for each line | 66 -- Split into multiple <value> tags, one for each line |
| 67 for line in value:gmatch("([^\r\n]+)\r?\n*") do | 67 for line in value:gmatch("([^\r\n]+)\r?\n*") do |
| 68 form:tag("value"):text(line):up(); | 68 form:tag("value"):text(line):up(); |
| 69 end | 69 end |
| 70 elseif field_type == "list-single" then | 70 elseif field_type == "list-single" then |
| 71 local has_default = false; | 71 if formtype ~= "result" then |
| 72 for _, val in ipairs(field.options or value) do | 72 local has_default = false; |
| 73 if type(val) == "table" then | 73 for _, val in ipairs(field.options or value) do |
| 74 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); | 74 if type(val) == "table" then |
| 75 if value == val.value or val.default and (not has_default) then | 75 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); |
| 76 form:tag("value"):text(val.value):up(); | 76 if value == val.value or val.default and (not has_default) then |
| 77 has_default = true; | 77 form:tag("value"):text(val.value):up(); |
| 78 has_default = true; | |
| 79 end | |
| 80 else | |
| 81 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); | |
| 78 end | 82 end |
| 79 else | |
| 80 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); | |
| 81 end | 83 end |
| 82 end | 84 end |
| 83 if field.options and value then | 85 if (field.options or formtype == "result") and value then |
| 84 form:tag("value"):text(value):up(); | 86 form:tag("value"):text(value):up(); |
| 85 end | 87 end |
| 86 elseif field_type == "list-multi" then | 88 elseif field_type == "list-multi" then |
| 87 for _, val in ipairs(field.options or value) do | 89 if formtype ~= "result" then |
| 88 if type(val) == "table" then | 90 for _, val in ipairs(field.options or value) do |
| 89 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); | 91 if type(val) == "table" then |
| 90 if not field.options and val.default then | 92 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); |
| 91 form:tag("value"):text(val.value):up(); | 93 if not field.options and val.default then |
| 94 form:tag("value"):text(val.value):up(); | |
| 95 end | |
| 96 else | |
| 97 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); | |
| 92 end | 98 end |
| 93 else | |
| 94 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); | |
| 95 end | 99 end |
| 96 end | 100 end |
| 97 if field.options and value then | 101 if (field.options or formtype == "result") and value then |
| 98 for _, val in ipairs(value) do | 102 for _, val in ipairs(value) do |
| 99 form:tag("value"):text(val):up(); | 103 form:tag("value"):text(val):up(); |
| 100 end | 104 end |
| 101 end | 105 end |
| 102 end | 106 end |