liquid_feedback_frontend

view app/main/registration/_register_form.lua @ 1679:ac45e0fe1221

Automatically assume dropdown item id from name when id is empty
author bsw
date Mon Sep 20 09:02:57 2021 +0200 (2021-09-20)
parents 63ce1a5c05c1
children af7b5bc0dec2
line source
1 for i, field in ipairs(config.self_registration.fields) do
2 local class = ""
3 local field_error = slot.get_content("self_registration__invalid_" .. field.name)
4 if field_error == "" then
5 field_error = nil
6 end
7 if field_error then
8 class = " is-invalid"
9 end
10 if not field.internal then
11 if field.type == "comment" then
12 ui.tag { content = field.label }
13 elseif field.name == "date_of_birth" then
14 local label = field.label
15 if field.optional then
16 label = label .. config.self_registration.optional_field_indicator
17 end
18 ui.tag{ tag = "label", attr = { style = "vertical-align: bottom; border-bottom: 1px solid rgba(0,0,0, 0.12); color: #777; font-size: 16px;" }, content = field.label .. ":" }
19 slot.put("   ")
20 local days = { { id = 0, name = _"day" } }
21 for i = 1, 31 do
22 table.insert(days, { id = i, name = i })
23 end
24 local months = {
25 { id = 0, name = _"month" },
26 { id = 1, name = "gennaio" },
27 { id = 2, name = "febbraio" },
28 { id = 3, name = "marzo" },
29 { id = 4, name = "aprile" },
30 { id = 5, name = "maggio" },
31 { id = 6, name = "giugno" },
32 { id = 7, name = "luglio" },
33 { id = 8, name = "agosto" },
34 { id = 9, name = "settembre" },
35 { id = 10, name = "ottobre" },
36 { id = 11, name = "novembre" },
37 { id = 12, name = "dicembre" },
38 }
39 if config.self_registration.lang == "en" then
40 months = {
41 { id = 0, name = _"month" },
42 { id = 1, name = "January" },
43 { id = 2, name = "February" },
44 { id = 3, name = "March" },
45 { id = 4, name = "April" },
46 { id = 5, name = "May" },
47 { id = 6, name = "June" },
48 { id = 7, name = "July" },
49 { id = 8, name = "August" },
50 { id = 9, name = "September" },
51 { id = 10, name = "October" },
52 { id = 11, name = "November" },
53 { id = 12, name = "December" },
54 }
55 end
56 if config.self_registration.lang == "de" then
57 months = {
58 { id = 0, name = _"month" },
59 { id = 1, name = "Januar" },
60 { id = 2, name = "Februar" },
61 { id = 3, name = "März" },
62 { id = 4, name = "April" },
63 { id = 5, name = "Mai" },
64 { id = 6, name = "Juni" },
65 { id = 7, name = "Juli" },
66 { id = 8, name = "August" },
67 { id = 9, name = "September" },
68 { id = 10, name = "Oktober" },
69 { id = 11, name = "November" },
70 { id = 12, name = "Dezember" },
71 }
72 end
73 local years = { { id = 0, name = _"year" } }
74 local min_age = config.self_registration.min_age or 16
75 for i = (atom.date:get_current()).year - min_age, 1900, -1 do
76 table.insert(years, { id = i, name = i })
77 end
78 ui.field.select{
79 container_attr = { style = "display: inline-block; " },
80 attr = { class = class },
81 foreign_records = days,
82 foreign_id = "id",
83 foreign_name = "name",
84 name = "verification_data_" .. field.name .. "_day",
85 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_day" })
86 }
87 slot.put("   ")
88 ui.field.select{
89 container_attr = { style = "display: inline-block; " },
90 attr = { class = class },
91 foreign_records = months,
92 foreign_id = "id",
93 foreign_name = "name",
94 name = "verification_data_" .. field.name .. "_month",
95 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_month" })
96 }
97 slot.put("   ")
98 ui.field.select{
99 container_attr = { style = "display: inline-block; " },
100 attr = { class = class },
101 foreign_records = years,
102 foreign_id = "id",
103 foreign_name = "name",
104 name = "verification_data_" .. field.name .. "_year",
105 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_year" })
106 }
107 slot.put("<br />")
109 elseif field.type == "dropdown" then
110 local options = { { id = "", name = "" } }
111 for i_options, option in ipairs(field.options) do
112 if not option.id then
113 option.id = option.name
114 end
115 table.insert(options, option)
116 end
117 ui.tag{ tag = "label", attr = { style = "vertical-align: bottom; border-bottom: 1px solid rgba(0,0,0, 0.12); color: #777; font-size: 16px;" }, content = field.label .. ":" }
118 slot.put(" &nbsp; ")
119 ui.field.select{
120 container_attr = { style = "display: inline-block; " },
121 attr = { class = class },
122 foreign_records = options,
123 foreign_id = "id",
124 foreign_name = "name",
125 name = "verification_data_" .. field.name,
126 value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
127 }
128 slot.put("<br />")
130 elseif field.type == "image" then
131 slot.put("<br />")
132 ui.tag{ tag = "label", attr = { style = "vertical-align: bottom; border-bottom: 1px solid rgba(0,0,0, 0.12); color: #777; font-size: 16px;" }, content = field.label .. ":" }
133 slot.put("<br />")
134 ui.script{ script = [[
135 function getFile(){
136 document.getElementById("fileInput").click();
137 }
138 function fileChoosen(obj){
139 var file = obj.value;
140 var fileName = file.split("\\");
141 var checked = false;
142 var label = "]] .. field.upload_label .. [[";
143 if (fileName[fileName.length-1].length > 0) {
144 label = fileName[fileName.length-1];
145 }
146 document.getElementById("fileBtn").innerHTML = label;
147 event.preventDefault();
148 }
149 ]] }
150 ui.tag{ tag = "input", attr = { id = "fileInput", style = "display: none;", type = "file", name = "verification_data_" .. field.name, onchange = "fileChoosen(this);" } }
151 ui.tag{
152 attr = { id = "fileBtn", class = "mdl-button mdl-js-button mdl-button--underlined", onclick = "getFile();" },
153 content = field.upload_label
154 }
155 if field.optional_checkbox then
156 slot.put(" &nbsp; ")
157 ui.tag{ tag = "label", attr = {
158 class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect",
159 style = "display: inline;",
160 ["for"] = "verification_data_" .. field.name .. "_optout"
161 },
162 content = function()
163 ui.tag{
164 tag = "input",
165 attr = {
166 type = "checkbox",
167 class = "mdl-checkbox__input",
168 id = "verification_data_" .. field.name .. "_optout",
169 name = "verification_data_" .. field.name .. "_optout",
170 value = "1",
171 style = "float: left;",
172 checked = request.get_param{ name = "verification_data_" .. field.name .. "_optout" } and "checked" or nil,
173 }
174 }
175 ui.tag{
176 attr = { class = "mdl-checkbox__label" },
177 content = field.optional_checkbox
178 }
179 end
180 }
181 end
183 elseif field.name == "unit" then
184 local units_selector = Unit:new_selector()
185 :add_where{ "active" }
186 :add_order_by("name")
187 if field.where then
188 units_selector:add_where(field.where)
189 end
190 local units = {}
191 if field.optional then
192 table.insert(units, {
193 id = "",
194 name = _"none"
195 })
196 end
197 for i_unit, unit in ipairs(units_selector:exec()) do
198 table.insert(units, unit)
199 end
200 ui.tag{ tag = "label", attr = { style = "vertical-align: bottom; border-bottom: 1px solid rgba(0,0,0, 0.12); color: #777; font-size: 16px;" }, content = field.label .. ":" }
201 slot.put(" &nbsp; ")
202 ui.field.select{
203 container_attr = { style = "display: inline-block; " },
204 foreign_records = units,
205 foreign_id = "id",
206 foreign_name = "name",
207 name = "verification_data_" .. field.name,
208 value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
209 }
210 slot.put("<br />")
211 else
212 if field.name == "mobile_phone" then
213 if config.self_registration.lang ~= "en" then
214 ui.tag{ content = "+39" }
215 slot.put(" ")
216 end
217 end
218 local label = field.label
219 if field.optional then
220 label = label .. config.self_registration.optional_field_indicator
221 end
222 ui.field.text{
223 container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class },
224 attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" },
225 label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name },
226 label = label,
227 name = "verification_data_" .. field.name,
228 value = request.get_param{ name = "verification_data_" .. field.name }
229 }
230 end
231 slot.put("<br />")
232 end
233 end

Impressum / About Us