Comparison

util/dataforms.lua @ 9090:56c52cb4d44e

util.dataforms: Exclude descriptive text fields from forms of type 'submit' The receiving end presumably already have the original form, so these potentially long text fields are of little value.
author Kim Alvefur <zash@zash.se>
date Fri, 03 Aug 2018 21:45:55 +0200
parent 9089:3a7a0b9f42f3
child 9091:519dea077d20
comparison
equal deleted inserted replaced
9089:3a7a0b9f42f3 9090:56c52cb4d44e
29 if not formtype then formtype = "form" end 29 if not formtype then formtype = "form" end
30 local form = st.stanza("x", { xmlns = xmlns_forms, type = formtype }); 30 local form = st.stanza("x", { xmlns = xmlns_forms, type = formtype });
31 if formtype == "cancel" then 31 if formtype == "cancel" then
32 return form; 32 return form;
33 end 33 end
34 if layout.title then 34 if formtype ~= "submit" then
35 form:tag("title"):text(layout.title):up(); 35 if layout.title then
36 end 36 form:tag("title"):text(layout.title):up();
37 if layout.instructions then 37 end
38 form:tag("instructions"):text(layout.instructions):up(); 38 if layout.instructions then
39 form:tag("instructions"):text(layout.instructions):up();
40 end
39 end 41 end
40 for _, field in ipairs(layout) do 42 for _, field in ipairs(layout) do
41 local field_type = field.type or "text-single"; 43 local field_type = field.type or "text-single";
42 -- Add field tag 44 -- Add field tag
43 form:tag("field", { type = field_type, var = field.name, label = field.label }); 45 form:tag("field", { type = field_type, var = field.name, label = formtype ~= "submit" and field.label or nil });
44 46
45 if field.desc then 47 if formtype ~= "submit" then
46 form:text_tag("desc", field.desc); 48 if field.desc then
49 form:text_tag("desc", field.desc);
50 end
47 end 51 end
48 52
49 local value; 53 local value;
50 if data and data[field.name] ~= nil then 54 if data and data[field.name] ~= nil then
51 value = data[field.name]; 55 value = data[field.name];
118 form:tag("uri", { type = val.type }):text(val.uri):up() 122 form:tag("uri", { type = val.type }):text(val.uri):up()
119 end 123 end
120 form:up(); 124 form:up();
121 end 125 end
122 126
123 if field.required then 127 if formtype == "form" and field.required then
124 form:tag("required"):up(); 128 form:tag("required"):up();
125 end 129 end
126 130
127 -- Jump back up to list of fields 131 -- Jump back up to list of fields
128 form:up(); 132 form:up();