Skip to content

Commit 1ca0481

Browse files
committed
Fix field pre-filling issues
1 parent e7e86d2 commit 1ca0481

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/components/QuestionTypes/BaseType.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
mounted() {
3838
if (this.question.answer) {
39-
this.dataValue = this.question.answer
39+
this.dataValue = this.answer = this.question.answer
4040
} else if (this.question.multiple) {
4141
this.dataValue = []
4242
}

src/components/QuestionTypes/MultipleChoiceType.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,15 @@
7070
},
7171
7272
mounted() {
73-
if (this.question.multiple) {
74-
this.dataValue = []
73+
if (this.question.answer) {
74+
// Set initial answer when we have one
75+
this.question.options.forEach(o => {
76+
const optionValue = o.choiceValue()
77+
78+
if (this.question.answer === optionValue || (Array.isArray(this.question.answer) && this.question.answer.indexOf(optionValue) !== -1)) {
79+
this.toggleAnswer(o)
80+
}
81+
})
7582
}
7683
7784
this.addKeyListener()

src/models/QuestionModel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ export default class QuestionModel {
124124
this.placeholder = 'yyyy-mm-dd'
125125
}
126126

127-
if (this.multiple) {
128-
this.answer = []
127+
if (this.multiple && !Array.isArray(this.answer)) {
128+
this.answer = this.answer ? [this.answer] : []
129129
}
130130
}
131131

0 commit comments

Comments
 (0)