|
418 | 418 | let
|
419 | 419 | index = 0,
|
420 | 420 | serialIndex = 0,
|
421 |
| - nextId |
| 421 | + nextId, |
| 422 | + activeIndex = this.activeQuestionIndex |
422 | 423 |
|
423 | 424 | do {
|
424 | 425 | let question = this.questionModels[index]
|
|
432 | 433 | ++index
|
433 | 434 | } else if (question.answered) {
|
434 | 435 | nextId = question.getJumpId()
|
| 436 | + |
435 | 437 | if (nextId) {
|
436 | 438 | if (nextId === '_submit') {
|
437 | 439 | index = this.questionModels.length
|
438 | 440 | } else {
|
439 | 441 | for (let i = 0; i < this.questionModels.length; i++) {
|
440 | 442 | if (this.questionModels[i].id === nextId) {
|
441 |
| - index = i |
| 443 | + if (i < index) { |
| 444 | + question.answered = false |
| 445 | + activeIndex = i |
| 446 | + ++index |
| 447 | + } else { |
| 448 | + index = i |
| 449 | + } |
442 | 450 | break
|
443 | 451 | }
|
444 | 452 | }
|
|
454 | 462 | } while (index < this.questionModels.length)
|
455 | 463 |
|
456 | 464 | this.questionListActivePath = questions
|
| 465 | + this.goToQuestion(activeIndex) |
457 | 466 | },
|
458 | 467 |
|
459 | 468 | /**
|
|
667 | 676 | */
|
668 | 677 | goToNextQuestion() {
|
669 | 678 | this.blurFocus()
|
| 679 | +
|
670 | 680 | if (this.isNextQuestionAvailable()) {
|
671 | 681 | this.emitEnter()
|
672 | 682 | }
|
673 | 683 |
|
674 | 684 | this.reverse = false
|
675 | 685 | },
|
676 | 686 |
|
| 687 | + /** |
| 688 | + * Jumps to question with specific index. |
| 689 | + */ |
| 690 | + goToQuestion(index) { |
| 691 | + if (isNaN(+index)) { |
| 692 | + let questionIndex = this.activeQuestionIndex |
| 693 | +
|
| 694 | + this.questionListActivePath.forEach((question, _index) => { |
| 695 | + if (question.id === index) { |
| 696 | + questionIndex = _index |
| 697 | + } |
| 698 | + }) |
| 699 | +
|
| 700 | + index = questionIndex; |
| 701 | + } |
| 702 | +
|
| 703 | + if (index !== this.activeQuestionIndex) { |
| 704 | + this.blurFocus() |
| 705 | + |
| 706 | + if (!this.submitted && index <= this.questionListActivePath.length - 1) { |
| 707 | + // Check if we can actually jump to the wanted question. |
| 708 | + do { |
| 709 | + const previousQuestion = index > 0 ? this.questionListActivePath[index - 1] : null |
| 710 | +
|
| 711 | + if (previousQuestion === null || previousQuestion.answered) { |
| 712 | + break |
| 713 | + } |
| 714 | +
|
| 715 | + --index |
| 716 | + } |
| 717 | + while (index > 0) |
| 718 | +
|
| 719 | + this.reverse = index < this.activeQuestionIndex |
| 720 | + this.activeQuestionIndex = index |
| 721 | +
|
| 722 | + this.checkTimer() |
| 723 | + } |
| 724 | + } |
| 725 | + }, |
| 726 | +
|
677 | 727 | /**
|
678 | 728 | * Removes focus from the currently focused DOM element.
|
679 | 729 | */
|
|
0 commit comments