liquid_feedback_frontend
changeset 1743:3d61fa0d6474
Add checkboxes to survey
author | bsw |
---|---|
date | Mon Oct 11 10:47:25 2021 +0200 (2021-10-11) |
parents | 9f96b7e6e5f2 |
children | f5c41bffb3ff |
files | app/main/survey/_action/answer.lua app/main/survey/participate.lua |
line diff
1.1 --- a/app/main/survey/_action/answer.lua Mon Oct 11 10:39:23 2021 +0200 1.2 +++ b/app/main/survey/_action/answer.lua Mon Oct 11 10:47:25 2021 +0200 1.3 @@ -31,9 +31,8 @@ 1.4 answer.survey_question_id = question.id 1.5 end 1.6 1.7 -local given_answer = param.get("answer") 1.8 - 1.9 if question.answer_type == "radio" then 1.10 + local given_answer = param.get("answer") 1.11 if not given_answer then 1.12 slot.put_into("error", _"Please choose an option!") 1.13 return false 1.14 @@ -48,9 +47,19 @@ 1.15 slot.put_into("error", _"Internal error 1") 1.16 return false 1.17 end 1.18 + answer.answer = given_answer 1.19 + 1.20 +if question.answer_type == "checkbox" then 1.21 + local answers = json.array() 1.22 + for i, answer_option in ipairs(question.answer_options) do 1.23 + local answer = param.get("answer_" .. answer_option) 1.24 + if answer then 1.25 + table.insert(answers, answer) 1.26 + end 1.27 + end 1.28 + answer.answer = answers 1.29 end 1.30 1.31 -answer.answer = given_answer 1.32 answer:save() 1.33 1.34 local question
2.1 --- a/app/main/survey/participate.lua Mon Oct 11 10:39:23 2021 +0200 2.2 +++ b/app/main/survey/participate.lua Mon Oct 11 10:47:25 2021 +0200 2.3 @@ -56,6 +56,7 @@ 2.4 }, 2.5 content = function() 2.6 ui.field.hidden{ name = "question_id", value = question.id } 2.7 + 2.8 if question.answer_type == "radio" then 2.9 for i, answer_option in ipairs(question.answer_options) do 2.10 ui.container{ content = function() 2.11 @@ -82,7 +83,35 @@ 2.12 end 2.13 } 2.14 end } 2.15 + 2.16 + if question.answer_type == "checkbox" then 2.17 + for i, answer_option in ipairs(question.answer_options) do 2.18 + ui.container{ content = function() 2.19 + ui.tag{ tag = "label", attr = { 2.20 + class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect", 2.21 + ["for"] = "answer_" .. i 2.22 + }, 2.23 + content = function() 2.24 + ui.tag{ 2.25 + tag = "input", 2.26 + attr = { 2.27 + id = "answer_" .. i, 2.28 + class = "mdl-checkbox__button", 2.29 + type = "checkbox", 2.30 + name = "answer_" .. answer_option, 2.31 + value = "1", 2.32 + checked = param.get("answer_" .. answer_option) and "checked" or nil, 2.33 + } 2.34 + } 2.35 + ui.tag{ 2.36 + attr = { class = "mdl-checkbox__label", ['for'] = "answer_" .. i }, 2.37 + content = answer_option 2.38 + } 2.39 + end 2.40 + } 2.41 + end } 2.42 end 2.43 + 2.44 slot.put("<br>") 2.45 ui.tag{ 2.46 tag = "input",