liquid_feedback_frontend
changeset 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 |
files | app/main/registration/_action/register.lua app/main/registration/_register_form.lua |
line diff
1.1 --- a/app/main/registration/_action/register.lua Mon Sep 20 09:39:26 2021 +0200 1.2 +++ b/app/main/registration/_action/register.lua Mon Sep 20 12:32:40 2021 +0200 1.3 @@ -140,6 +140,21 @@ 1.4 1.5 else 1.6 local value = param.get("verification_data_" .. field.name) 1.7 + if field.type == "dropdown" then 1.8 + local other_option_id 1.9 + for i_options, option in ipairs(field.options) do 1.10 + if not option.id then 1.11 + option.id = option.name 1.12 + end 1.13 + if option.other then 1.14 + other_option_id = option.id 1.15 + end 1.16 + end 1.17 + if other_option_id and other_option_id == value then 1.18 + value = param.get("verification_data_" .. field.name .. "_other") 1.19 + end 1.20 + end 1.21 + 1.22 local optional = false 1.23 if field.optional then 1.24 optional = true
2.1 --- a/app/main/registration/_register_form.lua Mon Sep 20 09:39:26 2021 +0200 2.2 +++ b/app/main/registration/_register_form.lua Mon Sep 20 12:32:40 2021 +0200 2.3 @@ -7,6 +7,12 @@ 2.4 if field_error then 2.5 class = " is-invalid" 2.6 end 2.7 + if field.title then 2.8 + ui.container{ attr = { style = "font-weight: bold;" }, content = field.title } 2.9 + end 2.10 + if field.text then 2.11 + ui.container{ content = field.text } 2.12 + end 2.13 if not field.internal then 2.14 if field.type == "comment" then 2.15 ui.tag { content = field.label } 2.16 @@ -108,23 +114,44 @@ 2.17 2.18 elseif field.type == "dropdown" then 2.19 local options = { { id = "", name = "" } } 2.20 + local other_option_id 2.21 for i_options, option in ipairs(field.options) do 2.22 if not option.id then 2.23 option.id = option.name 2.24 end 2.25 + if option.other then 2.26 + other_option_id = option.id 2.27 + end 2.28 table.insert(options, option) 2.29 end 2.30 - 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 .. ":" } 2.31 - slot.put(" ") 2.32 + if field.label then 2.33 + 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 .. ":" } 2.34 + slot.put(" ") 2.35 + end 2.36 + local onchange_script 2.37 + if other_option_id then 2.38 + 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'); };" 2.39 + end 2.40 ui.field.select{ 2.41 container_attr = { style = "display: inline-block; " }, 2.42 - attr = { class = class }, 2.43 + attr = { class = class, onchange = onchange_script }, 2.44 foreign_records = options, 2.45 foreign_id = "id", 2.46 foreign_name = "name", 2.47 name = "verification_data_" .. field.name, 2.48 value = tonumber(request.get_param{ name = "verification_data_" .. field.name }) 2.49 } 2.50 + if other_option_id then 2.51 + slot.put(" ") 2.52 + ui.field.text{ 2.53 + container_attr = { id = "lf-register__data_other_container_" .. field.name, class = "hidden mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class }, 2.54 + attr = { id = "lf-register__data_other_" .. field.name, class = "mdl-textfield__input" }, 2.55 + name = "verification_data_" .. field.name .. "_other", 2.56 + label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name }, 2.57 + label = field.name, 2.58 + value = request.get_param{ name = "verification_data_" .. field.name .. "_other" } 2.59 + } 2.60 + end 2.61 slot.put("<br />") 2.62 2.63 elseif field.type == "image" then