diff --git a/src/components/Questions/Question.vue b/src/components/Questions/Question.vue index 9f2ac0157abd4e8753da4f7cf656b1de20534e55..0920cf3d5313b3c960952aadbbb76514702adc68 100644 --- a/src/components/Questions/Question.vue +++ b/src/components/Questions/Question.vue @@ -135,10 +135,12 @@ export default { * @returns {Boolean} */ computedText() { + const text = this.text.replace('[n]', '').replace(']', '').split('[')[0] + if (this.mandatory) { - return this.text + ' *' + return text + ' *' } - return this.text + return text }, /** diff --git a/src/views/Submit.vue b/src/views/Submit.vue index acaa6bf4c554e9d0b268c8c20c0b810415069293..e5b03ebbaffe19b84658c232e9c8c0422209ad94 100644 --- a/src/views/Submit.vue +++ b/src/views/Submit.vue @@ -174,7 +174,7 @@ export default { message += ' ' + t('forms', 'An asterisk (*) indicates mandatory questions.') } - message += ' ' + this.logError + // message += ' ' + this.logError return message }, @@ -227,7 +227,17 @@ export default { this.$refs.submitButton.click() }, - checkQuestion(indexQ, saveIndex) { + checkAnswers(indexQ, saveIndex) { + const question = this.form.questions[indexQ] + + if (saveIndex && (!this.answers[question.id])) { + showError(t('forms', 'Answer is required')) + const errorMessage = { code: 499, message: 'Answer is required' } + throw errorMessage + } + }, + + checkQuestion(indexQ) { const question = this.form.questions[indexQ] const qTextSplit1 = question.text.replace('[n]', '').replace(']', '').split('[') // [1/1][1/2][1/3] @@ -241,16 +251,11 @@ export default { if (this.answers[qi]) { // "q1": None const answers = this.answers[qi].filter(answer => answer === ai) // "q1" : [a1,a2,a3,a4] - if (!answers.length) { + if (answers.length === 0) { continue // no answers, go to next question } else { return true } - } else { - if (saveIndex) { - showError(t('forms', 'Answer is required')) - throw 'Answer is required'; - } } } } @@ -264,8 +269,9 @@ export default { let index = this.questionIndex - if (this.checkQuestion(index)) { + if (this.checkQuestion(index, saveIndex)) { questionsArray.push(this.form.questions[index]) + this.checkAnswers(index, saveIndex) } while (index < this.form.questions.length - 1) { @@ -278,6 +284,7 @@ export default { if (this.checkQuestion(index, saveIndex)) { questionsArray.push(this.form.questions[index]) + this.checkAnswers(index, saveIndex) } } @@ -298,8 +305,8 @@ export default { try { if (this.questionIndex < this.form.questions.length - 1) { - const questions = this.getQuestions(true) - logError += ' ' + questions.length + this.getQuestions(true) + const questions = this.getQuestions(false) if (questions.length > 0) { return @@ -314,10 +321,10 @@ export default { this.questionIndex = 0 this.success = true } catch (error) { - this.questionIndex = 0 - this.logError = ' ' + error + // this.questionIndex = 0 + // this.logError += ' ' + error console.error(error) - showError(t('forms', 'There was an error submitting the form')) + showError(t('forms', 'There was an error in the form')) } finally { this.loading = false }