liquid_feedback_frontend

annotate app/main/registration/_register_form.lua @ 1684:b1cec2dcc035

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

Impressum / About Us