diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 61238a08..681f3bf9 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -961,7 +961,7 @@ class ApiController extends OCSController { $optionIndex = array_search($answer, array_column($question['options'], 'id')); if ($optionIndex !== false) { $answerText = $question['options'][$optionIndex]['text']; - } elseif (!empty($question['extraSettings']->allowOtherAnswer) && strpos($answer, Constants::QUESTION_EXTRASETTINGS_OTHER_PREFIX) === 0) { + } elseif (!empty($question['extraSettings']['allowOtherAnswer']) && strpos($answer, Constants::QUESTION_EXTRASETTINGS_OTHER_PREFIX) === 0) { $answerText = str_replace(Constants::QUESTION_EXTRASETTINGS_OTHER_PREFIX, "", $answer); } } else { diff --git a/lib/Service/SubmissionService.php b/lib/Service/SubmissionService.php index 04bc0875..5fbee91d 100644 --- a/lib/Service/SubmissionService.php +++ b/lib/Service/SubmissionService.php @@ -302,7 +302,7 @@ class SubmissionService { * @return boolean If the submission is valid */ public function validateSubmission(array $questions, array $answers): bool { - + // Check by questions foreach ($questions as $question) { $questionId = $question['id']; @@ -312,7 +312,7 @@ class SubmissionService { if ($question['isRequired'] && (!$questionAnswered || !array_filter($answers[$questionId], 'strlen') || - (!empty($question['extraSettings']->allowOtherAnswer) && !array_filter($answers[$questionId], fn ($value) => $value !== Constants::QUESTION_EXTRASETTINGS_OTHER_PREFIX))) + (!empty($question['extraSettings']['allowOtherAnswer']) && !array_filter($answers[$questionId], fn ($value) => $value !== Constants::QUESTION_EXTRASETTINGS_OTHER_PREFIX))) ) { return false; } @@ -334,7 +334,7 @@ class SubmissionService { } // Check if all answers are within the possible options - if (in_array($question['type'], Constants::ANSWER_TYPES_PREDEFINED) && empty($question['extraSettings']->allowOtherAnswer)) { + if (in_array($question['type'], Constants::ANSWER_TYPES_PREDEFINED) && empty($question['extraSettings']['allowOtherAnswer'])) { foreach ($answers[$questionId] as $answer) { // Search corresponding option, return false if non-existent if (array_search($answer, array_column($question['options'], 'id')) === false) { diff --git a/src/components/Questions/QuestionMultiple.vue b/src/components/Questions/QuestionMultiple.vue index 3ec4a9f1..33d4897b 100644 --- a/src/components/Questions/QuestionMultiple.vue +++ b/src/components/Questions/QuestionMultiple.vue @@ -48,7 +48,7 @@
- item.startsWith(this.QUESTION_EXTRASETTINGS_OTHER_PREFIX)) + const checkedOtherAnswer = this.values.filter(item => item.startsWith(this.QUESTION_EXTRASETTINGS_OTHER_PREFIX)) return checkedOtherAnswer[0] !== undefined }, }, @@ -229,24 +232,22 @@ export default { inputOtherAnswer() { if (this.isUnique) { - this.questionValues = this.valueOtherAnswer - this.onChange() + this.onChange(this.valueOtherAnswer) return } - this.questionValues = this.questionValues.filter(item => !item.startsWith(this.QUESTION_EXTRASETTINGS_OTHER_PREFIX)) - + const values = this.values.filter(item => !item.startsWith(this.QUESTION_EXTRASETTINGS_OTHER_PREFIX)) if (this.inputOtherAnswer !== '') { - this.questionValues.push(this.valueOtherAnswer) + values.push(this.valueOtherAnswer) } - this.onChange() + this.onChange(values) }, }, methods: { - onChange() { - this.$emit('update:values', this.isUnique ? [this.questionValues] : this.questionValues) + onChange(value) { + this.$emit('update:values', this.isUnique ? [value] : value) }, /** diff --git a/tests/Unit/Controller/ApiControllerTest.php b/tests/Unit/Controller/ApiControllerTest.php index 0e1bb03c..5c3c6bd6 100644 --- a/tests/Unit/Controller/ApiControllerTest.php +++ b/tests/Unit/Controller/ApiControllerTest.php @@ -572,7 +572,7 @@ class ApiControllerTest extends TestCase { [ 'id' => 2, 'type' => Constants::ANSWER_TYPE_MULTIPLE, - 'extraSettings' => (object)['allowOtherAnswer' => true], + 'extraSettings' => ['allowOtherAnswer' => true], 'options' => [ ['id' => 1, 'text' => 'test id 1'], ['id' => 2, 'text' => 'test id 2'], diff --git a/tests/Unit/Service/SubmissionServiceTest.php b/tests/Unit/Service/SubmissionServiceTest.php index d946f64d..ae812d45 100644 --- a/tests/Unit/Service/SubmissionServiceTest.php +++ b/tests/Unit/Service/SubmissionServiceTest.php @@ -564,7 +564,7 @@ class SubmissionServiceTest extends TestCase { 'required-empty-other-answer' => [ // Questions [ - ['id' => 1, 'type' => 'multiple_unique', 'isRequired' => true, 'extraSettings' => (object)['allowOtherAnswer' => true], 'options' => [ + ['id' => 1, 'type' => 'multiple_unique', 'isRequired' => true, 'extraSettings' => ['allowOtherAnswer' => true], 'options' => [ ['id' => 3] ]] ], @@ -664,7 +664,7 @@ class SubmissionServiceTest extends TestCase { ['id' => 6] ]], ['id' => 8, 'type' => 'time', 'isRequired' => false], - ['id' => 9, 'type' => 'multiple_unique', 'isRequired' => true, 'extraSettings' => (object)['allowOtherAnswer' => true], 'options' => [ + ['id' => 9, 'type' => 'multiple_unique', 'isRequired' => true, 'extraSettings' => ['allowOtherAnswer' => true], 'options' => [ ['id' => 3] ]], ],