liquid_feedback_frontend

view app/main/registration/_register_form.lua @ 1380:276718aedd90

Show label for drop down boxes
author bsw
date Wed Aug 08 17:38:23 2018 +0200 (2018-08-08)
parents 4b558772a66d
children 574eaf2ff457
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 slot.put("<br />")
13 local label = field.label
14 if field.optional then
15 label = label .. config.self_registration.optional_field_indicator
16 end
17 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 .. ":" }
18 slot.put(" &nbsp; ")
19 local days = { { id = 0, name = _"day" } }
20 for i = 1, 31 do
21 table.insert(days, { id = i, name = i })
22 end
23 local months = {
24 { id = 0, name = _"month" },
25 { id = 1, name = "gennaio" },
26 { id = 2, name = "febbraio" },
27 { id = 3, name = "marzo" },
28 { id = 4, name = "aprile" },
29 { id = 5, name = "maggio" },
30 { id = 6, name = "giugno" },
31 { id = 7, name = "luglio" },
32 { id = 8, name = "agosto" },
33 { id = 9, name = "settembre" },
34 { id = 10, name = "ottobre" },
35 { id = 11, name = "novembre" },
36 { id = 12, name = "dicembre" },
37 }
38 if config.self_registration.lang == "en" then
39 months = {
40 { id = 0, name = _"month" },
41 { id = 1, name = "January" },
42 { id = 2, name = "February" },
43 { id = 3, name = "March" },
44 { id = 4, name = "April" },
45 { id = 5, name = "May" },
46 { id = 6, name = "June" },
47 { id = 7, name = "July" },
48 { id = 8, name = "August" },
49 { id = 9, name = "September" },
50 { id = 10, name = "October" },
51 { id = 11, name = "November" },
52 { id = 12, name = "December" },
53 }
54 end
55 local years = { { id = 0, name = _"year" } }
56 for i = 2002, 1900, -1 do
57 table.insert(years, { id = i, name = i })
58 end
59 ui.field.select{
60 container_attr = { style = "display: inline-block; " },
61 attr = { class = class },
62 foreign_records = days,
63 foreign_id = "id",
64 foreign_name = "name",
65 name = "verification_data_" .. field.name .. "_day",
66 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_day" })
67 }
68 slot.put(" &nbsp; ")
69 ui.field.select{
70 container_attr = { style = "display: inline-block; " },
71 attr = { class = class },
72 foreign_records = months,
73 foreign_id = "id",
74 foreign_name = "name",
75 name = "verification_data_" .. field.name .. "_month",
76 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_month" })
77 }
78 slot.put(" &nbsp; ")
79 ui.field.select{
80 container_attr = { style = "display: inline-block; " },
81 attr = { class = class },
82 foreign_records = years,
83 foreign_id = "id",
84 foreign_name = "name",
85 name = "verification_data_" .. field.name .. "_year",
86 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_year" })
87 }
88 slot.put("<br />")
90 elseif field.type == "dropdown" then
91 local options = { { id = "", name = "" } }
92 for i_options, option in ipairs(field.options) do
93 table.insert(options, option)
94 end
95 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 .. ":" }
96 slot.put(" &nbsp; ")
97 ui.field.select{
98 container_attr = { style = "display: inline-block; " },
99 attr = { class = class },
100 foreign_records = options,
101 foreign_id = "id",
102 foreign_name = "name",
103 name = "verification_data_" .. field.name,
104 value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
105 }
107 elseif field.type == "image" then
108 ui.tag{ tag = "label", content = field.label }
109 slot.put(" ")
110 ui.tag{ tag = "input", attr = { type = "file", name = "verification_data_" .. field.name } }
111 if field.optional_checkbox then
112 ui.tag{ tag = "label", attr = {
113 class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect",
114 ["for"] = "verification_data_" .. field.name .. "_optout"
115 },
116 content = function()
117 ui.tag{
118 tag = "input",
119 attr = {
120 type = "checkbox",
121 class = "mdl-checkbox__input",
122 id = "verification_data_" .. field.name .. "_optout",
123 name = "verification_data_" .. field.name .. "_optout",
124 value = "1",
125 style = "float: left;",
126 checked = request.get_param{ name = "verification_data_" .. field.name .. "_optout" } and "checked" or nil,
127 }
128 }
129 ui.tag{
130 attr = { class = "mdl-checkbox__label" },
131 content = field.optional_checkbox
132 }
133 end
134 }
135 end
137 elseif field.name == "unit" then
138 local units_selector = Unit:new_selector()
139 :add_where{ "active" }
140 if field.where then
141 units_selector:add_where(field.where)
142 end
143 local units = {}
144 if field.optional then
145 table.insert(units, {
146 id = "",
147 name = _"None"
148 })
149 end
150 for i_unit, unit in ipairs(units_selector:exec()) do
151 table.insert(units, unit)
152 end
153 ui.field.select{
154 label = field.label,
155 foreign_records = units,
156 foreign_id = "id",
157 foreign_name = "name",
158 name = "verification_data_" .. field.name,
159 value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
160 }
161 else
162 if field.name == "mobile_phone" then
163 if config.self_registration.lang ~= "en" then
164 ui.tag{ content = "+39" }
165 slot.put(" ")
166 end
167 end
168 ui.field.text{
169 container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class },
170 attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" },
171 label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name },
172 label = field.label,
173 name = "verification_data_" .. field.name,
174 value = request.get_param{ name = "verification_data_" .. field.name }
175 }
176 end
177 slot.put("<br />")
178 end
179 end

Impressum / About Us