Mercurial > prosody-hg
comparison util/dataforms.lua @ 7442:156c95bfed0b
util.dataforms: Allow separation of options from values in list fields
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 27 May 2016 15:44:41 +0200 |
| parents | bcaa553de6e8 |
| children | 0db72fac2faa |
comparison
equal
deleted
inserted
replaced
| 7440:5424e24cdcb1 | 7442:156c95bfed0b |
|---|---|
| 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 local has_default = false; |
| 72 for _, val in ipairs(value) do | 72 for _, val in ipairs(field.options or value) do |
| 73 if type(val) == "table" then | 73 if type(val) == "table" then |
| 74 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); | 74 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); |
| 75 if val.default and (not has_default) then | 75 if value == val.value or field.options and val.default and (not has_default) then |
| 76 form:tag("value"):text(val.value):up(); | 76 form:tag("value"):text(val.value):up(); |
| 77 has_default = true; | 77 has_default = true; |
| 78 end | 78 end |
| 79 else | 79 else |
| 80 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); | 80 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); |
| 81 end | 81 end |
| 82 end | 82 end |
| 83 if field.options and value then | |
| 84 form:tag("value"):text(value):up(); | |
| 85 end | |
| 83 elseif field_type == "list-multi" then | 86 elseif field_type == "list-multi" then |
| 84 for _, val in ipairs(value) do | 87 for _, val in ipairs(field.options or value) do |
| 85 if type(val) == "table" then | 88 if type(val) == "table" then |
| 86 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); | 89 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); |
| 87 if val.default then | 90 if not field.options and val.default then |
| 88 form:tag("value"):text(val.value):up(); | 91 form:tag("value"):text(val.value):up(); |
| 89 end | 92 end |
| 90 else | 93 else |
| 91 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); | 94 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); |
| 95 end | |
| 96 end | |
| 97 if field.options and value then | |
| 98 for _, val in ipairs(value) do | |
| 99 form:tag("value"):text(val):up(); | |
| 92 end | 100 end |
| 93 end | 101 end |
| 94 end | 102 end |
| 95 end | 103 end |
| 96 | 104 |
