Skip to content

Commit bc47144

Browse files
committed
Fix skipping questions when quickly mashing keys
1 parent 681d98c commit bc47144

File tree

6 files changed

+52
-9
lines changed

6 files changed

+52
-9
lines changed

src/components/FlowForm.vue

+12-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
v-model="q.answer"
1515
v-on:answer="onQuestionAnswered"
1616
v-bind:reverse="reverse"
17+
v-bind:disabled="disabled"
18+
v-on:disable="setDisabled"
1719
/>
1820

1921
<slot></slot>
@@ -183,7 +185,8 @@
183185
reverse: false,
184186
timerOn: false,
185187
timerInterval: null,
186-
time: 0
188+
time: 0,
189+
disabled: false
187190
}
188191
},
189192
@@ -521,6 +524,10 @@
521524
},
522525
523526
emitEnter() {
527+
if (this.disabled) {
528+
return
529+
}
530+
524531
const q = this.activeQuestionComponent()
525532
526533
if (q) {
@@ -697,6 +704,10 @@
697704
}
698705
699706
return new Date(1000 * seconds).toISOString().substr(startIndex, length)
707+
},
708+
709+
setDisabled(state) {
710+
this.disabled = state
700711
}
701712
},
702713

src/components/FlowFormQuestion.vue

+27-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
v-bind:language="language"
2323
v-model="dataValue"
2424
v-bind:active="active"
25+
v-bind:disabled="disabled"
2526
v-on:next="onEnter"
2627
/>
2728
</span>
@@ -45,6 +46,7 @@
4546
v-bind:language="language"
4647
v-model="dataValue"
4748
v-bind:active="active"
49+
v-bind:disabled="disabled"
4850
v-on:next="onEnter"
4951
/>
5052
</div>
@@ -70,10 +72,11 @@
7072
v-on:click.prevent="onEnter"
7173
v-bind:aria-label="language.ariaOk"
7274
>
73-
<span v-if="question.type === QuestionType.SectionBreak">{{ language.continue }}</span>
74-
<span v-else-if="showSkip()">{{ language.skip }}</span>
75-
<span v-else>{{ language.ok }}</span>
75+
<span v-if="question.type === QuestionType.SectionBreak">{{ language.continue }}</span>
76+
<span v-else-if="showSkip()">{{ language.skip }}</span>
77+
<span v-else>{{ language.ok }}</span>
7678
</button>
79+
7780
<a
7881
class="f-enter-desc"
7982
href="#"
@@ -114,6 +117,7 @@
114117
115118
export default {
116119
name: 'FlowFormQuestion',
120+
117121
components: {
118122
FlowFormDateType,
119123
FlowFormDropdownType,
@@ -128,6 +132,7 @@
128132
FlowFormTextType,
129133
FlowFormUrlType
130134
},
135+
131136
props: {
132137
question: QuestionModel,
133138
language: LanguageModel,
@@ -139,27 +144,37 @@
139144
reverse: {
140145
type: Boolean,
141146
default: false
147+
},
148+
disabled: {
149+
type: Boolean,
150+
default: false
142151
}
143152
},
153+
144154
mixins: [
145155
IsMobile
146156
],
157+
147158
data() {
148159
return {
149160
QuestionType: QuestionType,
150161
dataValue: null,
151162
debounced: false
152163
}
153164
},
165+
154166
mounted() {
155167
this.focusField()
168+
156169
this.dataValue = this.question.answer
157170
158171
this.$refs.qanimate.addEventListener('animationend', this.onAnimationEnd)
159172
},
173+
160174
beforeDestroy() {
161175
this.$refs.qanimate.removeEventListener('animationend', this.onAnimationEnd)
162176
},
177+
163178
methods: {
164179
/**
165180
* Autofocus the input box of the current question
@@ -202,8 +217,13 @@
202217
checkAnswer(fn) {
203218
const q = this.$refs.questionComponent
204219
205-
if (q.isValid() && this.question.nextStepOnAnswer && !this.question.multiple) {
206-
this.debounce(() => fn(q), 350)
220+
if (q.isValid() && this.question.isMultipleChoiceType() && this.question.nextStepOnAnswer && !this.question.multiple) {
221+
this.$emit('disable', true)
222+
223+
this.debounce(() => {
224+
fn(q)
225+
this.$emit('disable', false)
226+
}, 350)
207227
} else {
208228
fn(q)
209229
}
@@ -256,7 +276,7 @@
256276
return true
257277
}
258278
259-
if (QuestionType.MultipleChoice && !this.question.multiple && this.question.nextStepOnAnswer) {
279+
if (this.question.isMultipleChoiceType() && !this.question.multiple && this.question.nextStepOnAnswer) {
260280
return false
261281
}
262282
@@ -290,6 +310,7 @@
290310
return q.showInvalid()
291311
}
292312
},
313+
293314
computed: {
294315
mainClasses: {
295316
cache: false,

src/components/QuestionTypes/BaseType.vue

+6
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@
1313
1414
export default {
1515
name: 'FlowFormBaseType',
16+
1617
props: {
1718
language: LanguageModel,
1819
question: QuestionModel,
1920
active: Boolean,
21+
disabled: Boolean,
2022
value: [String, Array, Boolean, Number, Object]
2123
},
24+
2225
mixins: [
2326
IsMobile,
2427
],
28+
2529
data() {
2630
return {
2731
dirty: false,
@@ -34,13 +38,15 @@
3438
canReceiveFocus: false
3539
}
3640
},
41+
3742
mounted() {
3843
if (this.question.answer) {
3944
this.dataValue = this.answer = this.question.answer
4045
} else if (this.question.multiple) {
4146
this.dataValue = []
4247
}
4348
},
49+
4450
methods: {
4551
/**
4652
* This method can be overriden in custom components to

src/components/QuestionTypes/DropdownType.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
}
7272
},
7373
onKeyUpListener($event) {
74-
if ($event.key === 'Enter' && this.isValid()) {
74+
if ($event.key === 'Enter' && this.isValid() && !this.disabled) {
7575
$event.stopPropagation()
7676
this._onEnter()
7777
this.$emit('next')

src/components/QuestionTypes/MultipleChoiceType.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@
174174
this.dataValue = option.selected ? optionValue : null
175175
}
176176
177-
if (this.isValid() && this.question.nextStepOnAnswer && !this.question.multiple) {
177+
178+
if (this.isValid() && this.question.nextStepOnAnswer && !this.question.multiple && !this.disabled) {
178179
this.$emit('next')
179180
}
180181

src/models/QuestionModel.js

+4
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,8 @@ export default class QuestionModel {
193193
}
194194
}
195195
}
196+
197+
isMultipleChoiceType() {
198+
return [QuestionType.MultipleChoice, QuestionType.MultiplePictureChoice].includes(this.type)
199+
}
196200
}

0 commit comments

Comments
 (0)