Skip to content

Commit 68d0e21

Browse files
committed
Add validation when question required
1 parent ce6343c commit 68d0e21

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/components/QuestionTypes/MatrixType.vue

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<label class="f-matrix-field f-matrix-radio">
3636
<input
3737
type="radio"
38+
v-bind:ref="el => inputList[row.id].push(el)"
3839
v-bind:name="row.id"
3940
v-bind:id="'c' + index + '-' + row.id"
4041
v-bind:aria-label="row.label"
@@ -57,6 +58,7 @@
5758
<label class="f-matrix-field f-matrix-checkbox">
5859
<input
5960
type="checkbox"
61+
v-bind:ref="el => inputList[row.id].push(el)"
6062
v-bind:id="'c' + index + '-' + row.id"
6163
v-bind:aria-label="row.label"
6264
v-bind:value="column.value"
@@ -97,7 +99,8 @@ export default {
9799
98100
data() {
99101
return {
100-
selected: {}
102+
selected: {},
103+
inputList: {}
101104
}
102105
},
103106
@@ -110,6 +113,11 @@ export default {
110113
} else if (this.question.answer) {
111114
this.selected = {...this.question.answer}
112115
}
116+
117+
// Setting input list for validation
118+
for (let row of this.question.rows) {
119+
this.inputList[row.id] = []
120+
}
113121
},
114122
115123
methods: {
@@ -118,7 +126,21 @@ export default {
118126
this.dataValue = this.selected
119127
this.onKeyDown()
120128
this.setAnswer(this.dataValue)
129+
},
130+
131+
validate() {
132+
if (!this.question.required) {
133+
return true
134+
}
135+
136+
const checked = inputs => inputs.some(input => input.checked)
137+
138+
if (!Object.values(this.inputList).every(value => checked(value))) {
139+
return false
140+
}
141+
142+
return true
121143
}
122-
}
144+
}
123145
}
124146
</script>

0 commit comments

Comments
 (0)