liquid_feedback_frontend
view app/main/registration/_register_form.lua @ 1373:18459491a4dc
Work around layout issue
| author | bsw |
|---|---|
| date | Wed Aug 08 17:16:23 2018 +0200 (2018-08-08) |
| parents | 635c6b7d2d0a |
| children | 866021907392 |
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(" ")
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(" ")
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(" ")
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 == "image" then
91 ui.tag{ tag = "label", content = field.label }
92 ui.tag{ tag = "input", attr = { type = "file", name = "verification_data_" .. field.name } }
93 if field.optional_checkbox then
94 ui.container{ content = function()
95 ui.tag{ tag = "input", attr = {
96 type = "checkbox",
97 name = "verification_data_" .. field.name .. "_optout",
98 checked = request.get_param{ name = "verification_data_" .. field.name .. "_optout" } and "checked" or nil,
99 } }
100 slot.put(" ")
101 ui.tag{ content = field.optional_checkbox }
102 end }
103 end
105 elseif field.name == "unit" then
106 local units_selector = Unit:new_selector()
107 :add_where{ "active" }
108 if field.where then
109 units_selector:add_where(field.where)
110 end
111 local units = {}
112 if field.optional then
113 table.insert(units, {
114 id = "",
115 name = _"None"
116 })
117 end
118 for i_unit, unit in ipairs(units_selector:exec()) do
119 table.insert(units, unit)
120 end
121 ui.field.select{
122 label = field.label,
123 foreign_records = units,
124 foreign_id = "id",
125 foreign_name = "name",
126 name = "verification_data_" .. field.name,
127 value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
128 }
129 else
130 if field.name == "mobile_phone" then
131 if config.self_registration.lang ~= "en" then
132 ui.tag{ content = "+39" }
133 slot.put(" ")
134 end
135 end
136 ui.field.text{
137 container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class },
138 attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" },
139 label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name },
140 label = field.label,
141 name = "verification_data_" .. field.name,
142 value = request.get_param{ name = "verification_data_" .. field.name }
143 }
144 end
145 slot.put("<br />")
146 end
147 end
