File tree Expand file tree Collapse file tree 2 files changed +33
-8
lines changed
Expand file tree Collapse file tree 2 files changed +33
-8
lines changed Original file line number Diff line number Diff line change 144144 data () {
145145 return {
146146 QuestionType: QuestionType,
147- dataValue: null
147+ dataValue: null ,
148+ debounced: false
148149 }
149150 },
150151 mounted () {
188189 * Emits "answer" event and calls "onEnter" method on Enter press
189190 */
190191 onEnter ($event ) {
192+ this .checkAnswer (this .emitAnswer )
193+ },
194+
195+ onTab ($event ) {
196+ this .checkAnswer (this .emitAnswerTab )
197+ },
198+
199+ checkAnswer (fn ) {
191200 const q = this .$refs .questionComponent
192201
202+ if (q .isValid () && this .question .nextStepOnAnswer && ! this .question .multiple ) {
203+ this .debounce (() => fn (q), 350 )
204+ } else {
205+ fn (q)
206+ }
207+ },
208+
209+ emitAnswer (q ) {
193210 if (q) {
194211 if (! q .focused ) {
195212 this .$emit (' answer' , q)
199216 }
200217 },
201218
202- onTab ($event ) {
203- const q = this .$refs .questionComponent
204-
219+ emitAnswerTab (q ) {
205220 if (q && this .question .type !== QuestionType .Date ) {
206221 this .returnFocus ()
207222 this .$emit (' answer' , q)
208223
209224 q .onEnter ()
210225 }
211226 },
227+
228+ debounce (fn , delay ) {
229+ let debounceTimer
230+ this .debounced = true
231+
232+ return (() => {
233+ clearTimeout (debounceTimer)
234+ debounceTimer = setTimeout (fn, delay)
235+ })()
236+ },
212237
213238 /**
214239 * Check if the "OK" button should be shown.
Original file line number Diff line number Diff line change 167167 } else {
168168 this .dataValue = option .selected ? option .choiceValue () : null
169169 }
170-
171- this .setAnswer (this .dataValue )
172-
170+
173171 if (this .isValid () && this .question .nextStepOnAnswer && ! this .question .multiple ) {
174- setTimeout (() => this .$emit (' next' ), 350 )
172+ this .$emit (' next' )
175173 }
174+
175+ this .setAnswer (this .dataValue )
176176 },
177177
178178 _removeAnswer (value ) {
You can’t perform that action at this time.
0 commit comments