# HG changeset patch # User bsw # Date 1632133960 -7200 # Node ID b1cec2dcc03576472370d213ba7ab50b4289a36b # Parent af7b5bc0dec2681c17e8ef5b7894a2f83c924317 Added support for other option in dropdown fields diff -r af7b5bc0dec2 -r b1cec2dcc035 app/main/registration/_action/register.lua --- a/app/main/registration/_action/register.lua Mon Sep 20 09:39:26 2021 +0200 +++ b/app/main/registration/_action/register.lua Mon Sep 20 12:32:40 2021 +0200 @@ -140,6 +140,21 @@ else local value = param.get("verification_data_" .. field.name) + if field.type == "dropdown" then + local other_option_id + for i_options, option in ipairs(field.options) do + if not option.id then + option.id = option.name + end + if option.other then + other_option_id = option.id + end + end + if other_option_id and other_option_id == value then + value = param.get("verification_data_" .. field.name .. "_other") + end + end + local optional = false if field.optional then optional = true diff -r af7b5bc0dec2 -r b1cec2dcc035 app/main/registration/_register_form.lua --- a/app/main/registration/_register_form.lua Mon Sep 20 09:39:26 2021 +0200 +++ b/app/main/registration/_register_form.lua Mon Sep 20 12:32:40 2021 +0200 @@ -7,6 +7,12 @@ if field_error then class = " is-invalid" end + if field.title then + ui.container{ attr = { style = "font-weight: bold;" }, content = field.title } + end + if field.text then + ui.container{ content = field.text } + end if not field.internal then if field.type == "comment" then ui.tag { content = field.label } @@ -108,23 +114,44 @@ elseif field.type == "dropdown" then local options = { { id = "", name = "" } } + local other_option_id for i_options, option in ipairs(field.options) do if not option.id then option.id = option.name end + if option.other then + other_option_id = option.id + end table.insert(options, option) end - 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 .. ":" } - slot.put("   ") + if field.label then + 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 .. ":" } + slot.put("   ") + end + local onchange_script + if other_option_id then + 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'); };" + end ui.field.select{ container_attr = { style = "display: inline-block; " }, - attr = { class = class }, + attr = { class = class, onchange = onchange_script }, foreign_records = options, foreign_id = "id", foreign_name = "name", name = "verification_data_" .. field.name, value = tonumber(request.get_param{ name = "verification_data_" .. field.name }) } + if other_option_id then + slot.put(" ") + ui.field.text{ + container_attr = { id = "lf-register__data_other_container_" .. field.name, class = "hidden mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class }, + attr = { id = "lf-register__data_other_" .. field.name, class = "mdl-textfield__input" }, + name = "verification_data_" .. field.name .. "_other", + label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name }, + label = field.name, + value = request.get_param{ name = "verification_data_" .. field.name .. "_other" } + } + end slot.put("
") elseif field.type == "image" then