Software /
code /
prosody
Comparison
util/dataforms.lua @ 9242:68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
This should allow the usage of long prefixes and namespace-like names to
be contained to the XML representation of the form, so that the code can
use more convenient names.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 01 Sep 2018 01:24:46 +0200 |
parent | 9121:e5eb36ee07a2 |
child | 9243:a4c52e304e6f |
comparison
equal
deleted
inserted
replaced
9241:2d82a926826f | 9242:68694c1bd960 |
---|---|
40 end | 40 end |
41 end | 41 end |
42 for _, field in ipairs(layout) do | 42 for _, field in ipairs(layout) do |
43 local field_type = field.type or "text-single"; | 43 local field_type = field.type or "text-single"; |
44 -- Add field tag | 44 -- Add field tag |
45 form:tag("field", { type = field_type, var = field.name, label = formtype ~= "submit" and field.label or nil }); | 45 form:tag("field", { type = field_type, var = field.var or field.name, label = formtype ~= "submit" and field.label or nil }); |
46 | 46 |
47 if formtype ~= "submit" then | 47 if formtype ~= "submit" then |
48 if field.desc then | 48 if field.desc then |
49 form:text_tag("desc", field.desc); | 49 form:text_tag("desc", field.desc); |
50 end | 50 end |
148 local present = {}; | 148 local present = {}; |
149 | 149 |
150 for _, field in ipairs(layout) do | 150 for _, field in ipairs(layout) do |
151 local tag; | 151 local tag; |
152 for field_tag in stanza:childtags("field") do | 152 for field_tag in stanza:childtags("field") do |
153 if field.name == field_tag.attr.var then | 153 if (field.var or field.name) == field_tag.attr.var then |
154 tag = field_tag; | 154 tag = field_tag; |
155 break; | 155 break; |
156 end | 156 end |
157 end | 157 end |
158 | 158 |