Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/questionnaire/Example.vue
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,6 @@
// we need to implement the "keyup" listener manually.

if ($event.key === 'Enter' && this.completed && !this.submitted) {
// Set `submitted` to true so the form knows not to allow back/forward
// navigation anymore.
this.$refs.flowform.submitted = true
this.onSendData()
}
},
Expand All @@ -250,6 +247,10 @@
},

onSendData() {
// Set `submitted` to true so the form knows not to allow back/forward
// navigation anymore.
this.$refs.flowform.submitted = true

this.submitted = true

/* eslint-disable-next-line no-unused-vars */
Expand Down
6 changes: 5 additions & 1 deletion examples/quiz/Example.vue
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@
},

onQuizSubmit() {
this.submitted = true
// Set `submitted` to true so the form knows not to allow back/forward
// navigation anymore.
this.$refs.flowform.submitted = true

this.submitted = true
this.calculateScore()
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/assets/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,9 @@ span.faux-form {
margin-top: 28px;
}

span.f-sub + .f-answer.full-width, div.field-sectionbreaktype .f-answer {
margin-top: 14px
span.f-sub + .f-answer.full-width,
div.field-sectionbreaktype .f-answer {
margin-top: 16px
}

span.f-empty {
Expand Down Expand Up @@ -349,7 +350,6 @@ h3,
}

@media screen and (max-width:767px) {

h2,
.fh2 {
font-size: 2.2rem;
Expand All @@ -359,7 +359,6 @@ h3,
}

@media screen and (max-width:479px), (max-height:400px) {

h2,
.fh2 {
font-size: 1.4rem;
Expand Down
72 changes: 56 additions & 16 deletions src/components/FlowForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@
}
},
mounted() {
document.addEventListener('keyup', this.onKeyListener, true)
document.addEventListener('keydown', this.onBackKeyListener)
document.addEventListener('keydown', this.onKeyDownListener)
document.addEventListener('keyup', this.onKeyUpListener, true)
window.addEventListener('beforeunload', this.onBeforeUnload)

this.setQuestions()
},
beforeDestroy() {
document.removeEventListener('keyup', this.onKeyListener, true)
document.removeEventListener('keydown', this.onBackKeyListener)
document.removeEventListener('keydown', this.onKeyDownListener)
document.removeEventListener('keyup', this.onKeyUpListener, true)
window.removeEventListener('beforeunload', this.onBeforeUnload)
},
computed: {
Expand Down Expand Up @@ -290,29 +290,54 @@
},

/**
* Global key listener, listens for Enter or Tab key events.
* Global key listeners, listen for Enter or Tab key events.
*/
onKeyListener(e) {
if (e.shiftKey) {
onKeyDownListener(e) {
if (e.key !== 'Tab' || this.submitted) {
return
}

if (e.key === 'Enter' || e.key === 'Tab') {
e.stopPropagation()

this.emitEnter()
this.reverse = false
}
},

onBackKeyListener(e) {
if (e.shiftKey && e.key === 'Tab' ) {
if (e.shiftKey) {
e.stopPropagation()
e.preventDefault()

this.goToPreviousQuestion()
} else {
e.preventDefault()

const q = this.activeQuestionComponent()

if (q.shouldFocus()) {
q.focusField()
} else {
e.stopPropagation()

this.emitTab()
this.reverse = false
}
}
},

onKeyUpListener(e) {
if (e.shiftKey || ['Tab', 'Enter'].indexOf(e.key) === -1 || this.submitted) {
return
}

const q = this.activeQuestionComponent()

if (e.key === 'Tab' && q.shouldFocus()) {
q.focusField()
} else {
if (e.key === 'Enter') {
this.emitEnter()
}

e.stopPropagation()
this.reverse = false
}
},

emitEnter() {
const q = this.activeQuestionComponent()

Expand All @@ -325,6 +350,17 @@
}
},

emitTab() {
const q = this.activeQuestionComponent()

if (q) {
// Send tab event to the current question component
q.onTab()
} else {
this.emitEnter()
}
},

submit() {
this.emitSubmit()
this.submitted = true
Expand All @@ -343,6 +379,10 @@
* can jump to it.
*/
isNextQuestionAvailable() {
if (this.submitted) {
return false
}

const q = this.activeQuestion

if (q && !q.required) {
Expand Down
26 changes: 26 additions & 0 deletions src/components/Question.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@
this.focusField()
},

shouldFocus() {
const q = this.$refs.questionComponent

return q && q.canReceiveFocus && !q.focused
},

returnFocus() {
const q = this.$refs.questionComponent

if (this.shouldFocus()) {
this.focusField()
}
},

/**
* Emits "answer" event and calls "onEnter" method on Enter press
*/
Expand All @@ -163,10 +177,22 @@
if (!q.focused) {
this.$emit('answer', q)
}

q.onEnter()
}
},

onTab($event) {
const q = this.$refs.questionComponent

if (q) {
this.returnFocus()
this.$emit('answer', q)

q.onEnter()
}
},

/**
* Check if the "OK" button should be shown.
*/
Expand Down
9 changes: 3 additions & 6 deletions src/components/QuestionTypes/BaseType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
enterPressed: false,
allowedChars: null,
alwaysAllowedKeys: ['ArrowLeft', 'ArrowRight', 'Delete', 'Backspace'],
focused: false
focused: false,
canReceiveFocus: false,
}
},
mounted() {
Expand Down Expand Up @@ -86,7 +87,7 @@
clearTimeout(this.timeoutId)

if ($event) {
if ($event.key === 'Enter') {
if ($event.key === 'Enter' && !$event.shiftKey) {
this.unsetFocus()
}

Expand Down Expand Up @@ -156,10 +157,6 @@
}
},
computed: {
editingFinished() {
return true
},

placeholder() {
return this.question.placeholder || this.language.placeholder
},
Expand Down
10 changes: 5 additions & 5 deletions src/components/QuestionTypes/LongTextType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
components: {
TextareaAutosize
},
data () {
return {
canReceiveFocus: true
}
},
mounted() {
window.addEventListener('resize', this.onResizeListener)
},
Expand Down Expand Up @@ -63,11 +68,6 @@
this._onEnter()
}
}
},
computed: {
editingFinished() {
return !this.isMobile
}
}
}
</script>
3 changes: 2 additions & 1 deletion src/components/QuestionTypes/PhoneType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
name: QuestionType.Phone,
data() {
return {
inputType: 'tel'
inputType: 'tel',
canReceiveFocus: true
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/QuestionTypes/TextType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
name: QuestionType.Text,
data() {
return {
inputType: 'text'
inputType: 'text',
canReceiveFocus: true
}
}
}
Expand Down