liquid_feedback_frontend

diff 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
line diff
     1.1 --- a/app/main/registration/_register_form.lua	Mon Sep 20 09:39:26 2021 +0200
     1.2 +++ b/app/main/registration/_register_form.lua	Mon Sep 20 12:32:40 2021 +0200
     1.3 @@ -7,6 +7,12 @@
     1.4    if field_error then
     1.5      class = " is-invalid"
     1.6    end
     1.7 +  if field.title then
     1.8 +    ui.container{ attr = { style = "font-weight: bold;" }, content = field.title }
     1.9 +  end
    1.10 +  if field.text then
    1.11 +    ui.container{ content = field.text }
    1.12 +  end
    1.13    if not field.internal then
    1.14      if field.type == "comment" then
    1.15        ui.tag { content = field.label }
    1.16 @@ -108,23 +114,44 @@
    1.17      
    1.18      elseif field.type == "dropdown" then
    1.19        local options = { { id = "", name = "" } }
    1.20 +      local other_option_id
    1.21        for i_options, option in ipairs(field.options) do
    1.22          if not option.id then
    1.23            option.id = option.name
    1.24          end
    1.25 +        if option.other then
    1.26 +          other_option_id = option.id
    1.27 +        end
    1.28          table.insert(options, option)
    1.29        end
    1.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 .. ":" }
    1.31 -      slot.put("   ")
    1.32 +      if field.label then
    1.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 .. ":" }
    1.34 +        slot.put("   ")
    1.35 +      end
    1.36 +      local onchange_script
    1.37 +      if other_option_id then
    1.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'); };"
    1.39 +      end
    1.40        ui.field.select{
    1.41          container_attr = { style = "display: inline-block; " },
    1.42 -        attr = { class = class },
    1.43 +        attr = { class = class, onchange = onchange_script },
    1.44          foreign_records = options,
    1.45          foreign_id = "id",
    1.46          foreign_name = "name",
    1.47          name = "verification_data_" .. field.name,
    1.48          value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
    1.49        }
    1.50 +      if other_option_id then
    1.51 +        slot.put(" ")
    1.52 +        ui.field.text{
    1.53 +          container_attr = { id = "lf-register__data_other_container_" .. field.name, class = "hidden mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class },
    1.54 +          attr = { id = "lf-register__data_other_" .. field.name, class = "mdl-textfield__input" },
    1.55 +          name = "verification_data_" .. field.name .. "_other",
    1.56 +        label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name },
    1.57 +          label = field.name,
    1.58 +          value = request.get_param{ name = "verification_data_" .. field.name .. "_other" }
    1.59 +        }
    1.60 +      end
    1.61        slot.put("<br />")
    1.62  
    1.63      elseif field.type == "image" then

Impressum / About Us