liquid_feedback_frontend
diff app/main/registration/_register_form.lua @ 1843:b01d9920371b
merge
| author | jbe |
|---|---|
| date | Thu Feb 03 15:57:22 2022 +0100 (2022-02-03) |
| parents | e5756a575dde |
| children |
line diff
1.1 --- a/app/main/registration/_register_form.lua Thu Feb 03 15:54:23 2022 +0100 1.2 +++ b/app/main/registration/_register_form.lua Thu Feb 03 15:57:22 2022 +0100 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,20 +114,96 @@ 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 + value = request.get_param{ name = "verification_data_" .. field.name } 1.50 } 1.51 + if other_option_id then 1.52 + slot.put(" ") 1.53 + ui.field.text{ 1.54 + container_attr = { id = "lf-register__data_other_container_" .. field.name, class = "hidden mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class }, 1.55 + attr = { id = "lf-register__data_other_" .. field.name, class = "mdl-textfield__input" }, 1.56 + name = "verification_data_" .. field.name .. "_other", 1.57 + label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name }, 1.58 + label = field.name, 1.59 + value = request.get_param{ name = "verification_data_" .. field.name .. "_other" } 1.60 + } 1.61 + end 1.62 + slot.put("<br />") 1.63 + 1.64 + elseif field.type == "multiselect" then 1.65 + local options = { { id = "", name = "" } } 1.66 + local other_option_id 1.67 + for i_options, option in ipairs(field.options) do 1.68 + if not option.id then 1.69 + option.id = option.name 1.70 + end 1.71 + local onchange_script 1.72 + if option.other then 1.73 + onchange_script = "var el = document.getElementById('lf-register__data_other_container_" .. field.name .. "'); if (this.checked) { console.log(el); el.classList.remove('hidden'); } else { el.classList.add('hidden'); };" 1.74 + end 1.75 + ui.container{ content = function() 1.76 + ui.tag{ tag = "label", attr = { 1.77 + class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect", 1.78 + style = "display: inline;", 1.79 + ["for"] = "verification_data_" .. field.name .. "__" .. option.id, 1.80 + }, 1.81 + content = function() 1.82 + ui.tag{ 1.83 + tag = "input", 1.84 + attr = { 1.85 + type = "checkbox", 1.86 + class = "mdl-checkbox__input", 1.87 + onchange = onchange_script, 1.88 + id = "verification_data_" .. field.name .. "__" .. option.id, 1.89 + name = "verification_data_" .. field.name .. "__" .. option.id, 1.90 + value = "1", 1.91 + style = "float: left;", 1.92 + checked = request.get_param{ name = "verification_data_" .. field.name .. "__" .. option.id } and "checked" or nil, 1.93 + } 1.94 + } 1.95 + ui.tag{ 1.96 + attr = { class = "mdl-checkbox__label" }, 1.97 + content = option.name 1.98 + } 1.99 + end 1.100 + } 1.101 + end } 1.102 + if option.other then 1.103 + slot.put(" ") 1.104 + ui.field.text{ 1.105 + container_attr = { id = "lf-register__data_other_container_" .. field.name, class = "hidden mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class }, 1.106 + attr = { id = "lf-register__data_other_" .. field.name, class = "mdl-textfield__input" }, 1.107 + name = "verification_data_" .. field.name .. "_other", 1.108 + label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name }, 1.109 + label = field.name, 1.110 + value = request.get_param{ name = "verification_data_" .. field.name .. "_other" } 1.111 + } 1.112 + end 1.113 + end 1.114 slot.put("<br />") 1.115 1.116 elseif field.type == "image" then 1.117 @@ -184,7 +266,7 @@ 1.118 if field.where then 1.119 units_selector:add_where(field.where) 1.120 end 1.121 - local units = {} 1.122 + local units = { { id = "", name = "" } } 1.123 if field.optional then 1.124 table.insert(units, { 1.125 id = "",