fix: choice questions validations
This commit is contained in:
@@ -12,9 +12,9 @@
|
||||
id="existing"
|
||||
value="existing"
|
||||
v-model="questionType"
|
||||
class="w-3 h-3 accent-gray-900"
|
||||
class="w-3 h-3 cursor-pointer"
|
||||
/>
|
||||
<label for="existing">
|
||||
<label for="existing" class="cursor-pointer">
|
||||
{{ __('Add an existing question') }}
|
||||
</label>
|
||||
</div>
|
||||
@@ -25,9 +25,9 @@
|
||||
id="new"
|
||||
value="new"
|
||||
v-model="questionType"
|
||||
class="w-3 h-3"
|
||||
class="w-3 h-3 cursor-pointer"
|
||||
/>
|
||||
<label for="new">
|
||||
<label for="new" class="cursor-pointer">
|
||||
{{ __('Create a new question') }}
|
||||
</label>
|
||||
</div>
|
||||
@@ -127,7 +127,7 @@ const populateFields = () => {
|
||||
let counter = 1
|
||||
fields.forEach((field) => {
|
||||
while (counter <= 4) {
|
||||
question[`${field}_${counter}`] = field === 'is_correct' ? false : ''
|
||||
question[`${field}_${counter}`] = field === 'is_correct' ? false : null
|
||||
counter++
|
||||
}
|
||||
})
|
||||
|
||||
@@ -141,6 +141,7 @@
|
||||
v-slot="{ idx, column, item }"
|
||||
v-for="row in quiz.questions"
|
||||
@click="openQuestionModal(row)"
|
||||
class="cursor-pointer"
|
||||
>
|
||||
<ListRowItem :item="item">
|
||||
<div
|
||||
|
||||
@@ -16,6 +16,7 @@ class LMSQuestion(Document):
|
||||
def validate_correct_answers(question):
|
||||
if question.type == "Choices":
|
||||
validate_duplicate_options(question)
|
||||
validate_minimum_options(question)
|
||||
validate_correct_options(question)
|
||||
elif question.type == "User Input":
|
||||
validate_possible_answer(question)
|
||||
@@ -42,6 +43,11 @@ def validate_correct_options(question):
|
||||
frappe.throw(_("At least one option must be correct for this question."))
|
||||
|
||||
|
||||
def validate_minimum_options(question):
|
||||
if question.type == "Choices" and (not question.option_1 or not question.option_2):
|
||||
frappe.throw(_("Minimum two options are required for multiple choice questions."))
|
||||
|
||||
|
||||
def validate_possible_answer(question):
|
||||
possible_answers = []
|
||||
possible_answers_fields = [
|
||||
|
||||
Reference in New Issue
Block a user