From 295281f4d9197a5042d49edc16a28fd4f627d14c Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 27 Jan 2021 16:59:32 +0100 Subject: [PATCH] wait #4224 @2 --- app/Models/Quiz.php | 4 ++++ app/SubForms/Question.php | 5 +++++ resources/quiz/js/main.js | 7 ++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Models/Quiz.php b/app/Models/Quiz.php index 53500f6b2..eccd2af8f 100644 --- a/app/Models/Quiz.php +++ b/app/Models/Quiz.php @@ -292,6 +292,9 @@ class Quiz extends CubistMagicAbstractModel if (!isset($question['type'])) { $question['type'] = 'multiple'; } + if (!isset($question['required'])) { + $question['required'] = true; + } if (!isset($question['count_for_score'])) { $question['count_for_score'] = true; } @@ -299,6 +302,7 @@ class Quiz extends CubistMagicAbstractModel if ($question['multiple']) { $xq->addAttribute('multiple', '1'); } + $xq->addAttribute('required', $question['required'] ? '1' : '0'); $xq->addAttribute('count', $question['count_for_score'] ? '1' : '0'); $xq->addAttribute('type', $question['type']); $xq->addAttribute('min_score', $question['min_score']); diff --git a/app/SubForms/Question.php b/app/SubForms/Question.php index ce7d452b2..11d58d97f 100644 --- a/app/SubForms/Question.php +++ b/app/SubForms/Question.php @@ -16,6 +16,11 @@ class Question extends SubForm 'label' => __('Intitulé de la question'), ]); + $this->addField(['name' => 'required', + 'type' => 'Checkbox', + 'default' => true, + 'label' => __('Réponse obligatoire')]); + $this->addField(['name' => 'report_label', 'type' => 'Text', 'label' => __('Intitulé de la question dans les rapports'), diff --git a/resources/quiz/js/main.js b/resources/quiz/js/main.js index 6225578c8..bda41f69c 100644 --- a/resources/quiz/js/main.js +++ b/resources/quiz/js/main.js @@ -146,6 +146,7 @@ $(correction).append(c); var q = $(question); + var required = $(q).attr('required') === '1' ? 'required' : ''; // Append answers var holder = $('
'); @@ -167,9 +168,9 @@ q.addClass('multiple'); } } else if (type === 'text' || type === "email") { - $(holder).append('') + $(holder).append('') } else if (type === 'textarea') { - $(holder).append('') + $(holder).append('') } $(q).find('.answers').append($(holder)); @@ -191,7 +192,7 @@ results += '

' + defaultMessage + '

'; results += '

' + passedMessage + '

'; results += '

' + failedMessage + '

'; - if(displayScore) { + if (displayScore) { results += '
' + getTranslation('totalQuestions') + ' ' + countQuestions + '
' + getTranslation('correctAnswers') + '
'; } results += ''; -- 2.39.5