Skip to content

Commit f0ccee8

Browse files
committed
Make dataValue and ChoiceOption.value null by default
1 parent 8386f8a commit f0ccee8

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

src/components/Question.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@
228228
return false
229229
}
230230
231-
// if there is no question referenced, or dataValue is still set to one of its defaults (null, from above; '' from the default ChoiceOption)
232-
// this allows a ChoiceOption value of false, but will not allow you to use null or '' as a value.
233-
if (!q || this.dataValue === null || this.dataValue === '') {
231+
// If there is no question referenced, or dataValue is still set to its default (null).
232+
// This allows a ChoiceOption value of false, but will not allow you to use null as a value.
233+
if (!q || this.dataValue === null) {
234234
return false
235235
}
236236
@@ -243,7 +243,7 @@
243243
showInvalid() {
244244
const q = this.$refs.questionComponent
245245
246-
if (!q || this.dataValue === null || this.dataValue === '') { // see comment above regarding null options
246+
if (!q || this.dataValue === null) {
247247
return false
248248
}
249249

src/components/QuestionTypes/BaseType.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
data() {
2626
return {
2727
dirty: false,
28-
dataValue: '',
28+
dataValue: null,
2929
answer: null,
3030
enterPressed: false,
3131
allowedChars: null,

src/components/QuestionTypes/MultipleChoiceType.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,20 @@
222222
stopEditOther() {
223223
this.editingOther = false
224224
}
225+
},
226+
227+
computed: {
228+
hasValue() {
229+
if (this.question.options.filter(o => o.selected).length) {
230+
return true
231+
}
232+
233+
if (this.question.allowOther) {
234+
return this.question.other && this.question.other.trim().length > 0
235+
}
236+
237+
return false
238+
}
225239
}
226240
}
227241
</script>

src/models/QuestionModel.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const MaskPresets = Object.freeze({
3535
export class ChoiceOption {
3636
constructor(options) {
3737
this.label = ''
38-
this.value = ''
38+
this.value = null
3939
this.selected = false
4040

4141
Object.assign(this, options)
@@ -46,9 +46,9 @@ export class ChoiceOption {
4646
}
4747

4848
choiceValue() {
49-
// returns the value if it's anything other than the default (an empty string).
50-
// returns label if the value has not been set.
51-
return this.value !== '' ? this.value : this.label
49+
// Returns the value if it's anything other than the default (null).
50+
// Returns label if the value has not been set.
51+
return this.value !== null ? this.value : this.label
5252
}
5353

5454
toggle() {

0 commit comments

Comments
 (0)