liquid_feedback_frontend
view app/main/registration/_register_form.lua @ 1405:6d81bd595b51
Show optional indication in registration form fields
| author | bsw |
|---|---|
| date | Wed Aug 15 10:05:52 2018 +0200 (2018-08-15) |
| parents | f99e7df399e6 |
| children | 428fa9c202b6 |
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.name == "date_of_birth" then
12 local label = field.label
13 if field.optional then
14 label = label .. config.self_registration.optional_field_indicator
15 end
16 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 .. ":" }
17 slot.put(" ")
18 local days = { { id = 0, name = _"day" } }
19 for i = 1, 31 do
20 table.insert(days, { id = i, name = i })
21 end
22 local months = {
23 { id = 0, name = _"month" },
24 { id = 1, name = "gennaio" },
25 { id = 2, name = "febbraio" },
26 { id = 3, name = "marzo" },
27 { id = 4, name = "aprile" },
28 { id = 5, name = "maggio" },
29 { id = 6, name = "giugno" },
30 { id = 7, name = "luglio" },
31 { id = 8, name = "agosto" },
32 { id = 9, name = "settembre" },
33 { id = 10, name = "ottobre" },
34 { id = 11, name = "novembre" },
35 { id = 12, name = "dicembre" },
36 }
37 if config.self_registration.lang == "en" then
38 months = {
39 { id = 0, name = _"month" },
40 { id = 1, name = "January" },
41 { id = 2, name = "February" },
42 { id = 3, name = "March" },
43 { id = 4, name = "April" },
44 { id = 5, name = "May" },
45 { id = 6, name = "June" },
46 { id = 7, name = "July" },
47 { id = 8, name = "August" },
48 { id = 9, name = "September" },
49 { id = 10, name = "October" },
50 { id = 11, name = "November" },
51 { id = 12, name = "December" },
52 }
53 end
54 local years = { { id = 0, name = _"year" } }
55 for i = 2002, 1900, -1 do
56 table.insert(years, { id = i, name = i })
57 end
58 ui.field.select{
59 container_attr = { style = "display: inline-block; " },
60 attr = { class = class },
61 foreign_records = days,
62 foreign_id = "id",
63 foreign_name = "name",
64 name = "verification_data_" .. field.name .. "_day",
65 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_day" })
66 }
67 slot.put(" ")
68 ui.field.select{
69 container_attr = { style = "display: inline-block; " },
70 attr = { class = class },
71 foreign_records = months,
72 foreign_id = "id",
73 foreign_name = "name",
74 name = "verification_data_" .. field.name .. "_month",
75 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_month" })
76 }
77 slot.put(" ")
78 ui.field.select{
79 container_attr = { style = "display: inline-block; " },
80 attr = { class = class },
81 foreign_records = years,
82 foreign_id = "id",
83 foreign_name = "name",
84 name = "verification_data_" .. field.name .. "_year",
85 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_year" })
86 }
87 slot.put("<br />")
89 elseif field.type == "dropdown" then
90 local options = { { id = "", name = "" } }
91 for i_options, option in ipairs(field.options) do
92 table.insert(options, option)
93 end
94 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 .. ":" }
95 slot.put(" ")
96 ui.field.select{
97 container_attr = { style = "display: inline-block; " },
98 attr = { class = class },
99 foreign_records = options,
100 foreign_id = "id",
101 foreign_name = "name",
102 name = "verification_data_" .. field.name,
103 value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
104 }
105 slot.put("<br />")
107 elseif field.type == "image" then
108 slot.put("<br />")
109 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 .. ":" }
110 slot.put("<br />")
111 ui.script{ script = [[
112 function getFile(){
113 document.getElementById("fileInput").click();
114 }
115 function fileChoosen(obj){
116 var file = obj.value;
117 var fileName = file.split("\\");
118 var checked = false;
119 var label = "]] .. field.upload_label .. [[";
120 if (fileName[fileName.length-1].length > 0) {
121 label = fileName[fileName.length-1];
122 }
123 document.getElementById("fileBtn").innerHTML = label;
124 event.preventDefault();
125 }
126 ]] }
127 ui.tag{ tag = "input", attr = { id = "fileInput", style = "display: none;", type = "file", name = "verification_data_" .. field.name, onchange = "fileChoosen(this);" } }
128 ui.tag{
129 attr = { id = "fileBtn", class = "mdl-button mdl-js-button mdl-button--underlined", onclick = "getFile();" },
130 content = field.upload_label
131 }
132 if field.optional_checkbox then
133 slot.put(" ")
134 ui.tag{ tag = "label", attr = {
135 class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect",
136 style = "display: inline;",
137 ["for"] = "verification_data_" .. field.name .. "_optout"
138 },
139 content = function()
140 ui.tag{
141 tag = "input",
142 attr = {
143 type = "checkbox",
144 class = "mdl-checkbox__input",
145 id = "verification_data_" .. field.name .. "_optout",
146 name = "verification_data_" .. field.name .. "_optout",
147 value = "1",
148 style = "float: left;",
149 checked = request.get_param{ name = "verification_data_" .. field.name .. "_optout" } and "checked" or nil,
150 }
151 }
152 ui.tag{
153 attr = { class = "mdl-checkbox__label" },
154 content = field.optional_checkbox
155 }
156 end
157 }
158 end
160 elseif field.name == "unit" then
161 local units_selector = Unit:new_selector()
162 :add_where{ "active" }
163 if field.where then
164 units_selector:add_where(field.where)
165 end
166 local units = {}
167 if field.optional then
168 table.insert(units, {
169 id = "",
170 name = _"none"
171 })
172 end
173 for i_unit, unit in ipairs(units_selector:exec()) do
174 table.insert(units, unit)
175 end
176 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 .. ":" }
177 slot.put(" ")
178 ui.field.select{
179 container_attr = { style = "display: inline-block; " },
180 foreign_records = units,
181 foreign_id = "id",
182 foreign_name = "name",
183 name = "verification_data_" .. field.name,
184 value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
185 }
186 slot.put("<br />")
187 else
188 if field.name == "mobile_phone" then
189 if config.self_registration.lang ~= "en" then
190 ui.tag{ content = "+39" }
191 slot.put(" ")
192 end
193 end
194 local label = field.label
195 if field.optional then
196 label = label .. config.self_registration.optional_field_indicator
197 end
198 ui.field.text{
199 container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class },
200 attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" },
201 label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name },
202 label = field.label,
203 name = "verification_data_" .. field.name,
204 value = request.get_param{ name = "verification_data_" .. field.name }
205 }
206 end
207 slot.put("<br />")
208 end
209 end
