liquid_feedback_frontend
diff app/main/survey/_action/answer.lua @ 1743:3d61fa0d6474
Add checkboxes to survey
author | bsw |
---|---|
date | Mon Oct 11 10:47:25 2021 +0200 (2021-10-11) |
parents | 5a8a09119865 |
children | f5c41bffb3ff |
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