|
1 | 1 | // Single question template and logic |
2 | 2 |
|
3 | 3 | <template> |
4 | | - <div class="animate q-form" v-bind:class="mainClasses"> |
5 | | - <div class="q-inner" ref="qinner"> |
| 4 | + <div class="animate q-form" v-bind:class="mainClasses" ref="qanimate"> |
| 5 | + <div class="q-inner"> |
6 | 6 | <div v-bind:class="{'section-wrap': question.type === QuestionType.SectionBreak}"> |
7 | 7 | <div v-bind:class="{'fh2': question.type !== QuestionType.SectionBreak}"> |
8 | 8 | <span class="f-title" v-if="question.tagline">{{ question.tagline }}</span> |
|
31 | 31 | <span class="f-sub" v-if="question.subtitle || question.type === QuestionType.LongText || question.multiple"> |
32 | 32 | <span v-if="question.subtitle">{{ question.subtitle }}</span> |
33 | 33 |
|
34 | | - <span class="f-help" v-if="question.type === QuestionType.LongText">{{ question.helpText || language.longTextHelpText }}</span> |
| 34 | + <span class="f-help" v-if="question.type === QuestionType.LongText && !isMobile">{{ question.helpText || language.longTextHelpText }}</span> |
35 | 35 |
|
36 | 36 | <span class="f-help" v-if="question.multiple">{{ question.helpText || language.multipleChoiceHelpText }}</span> |
37 | 37 | </span> |
|
65 | 65 | <span v-else>{{ language.ok }}</span> |
66 | 66 | </div> |
67 | 67 |
|
68 | | - <span class="f-enter-desc">{{ language.pressEnter }}</span> |
| 68 | + <span class="f-enter-desc" v-if="question.type !== QuestionType.LongText || !isMobile">{{ language.pressEnter }}</span> |
69 | 69 | </a> |
70 | 70 |
|
71 | 71 | <div v-if="showInvalid()" class="f-invalid" role="alert" aria-live="assertive">{{ language.invalidPrompt }}</div> |
|
91 | 91 | import FlowFormSectionBreakType from './QuestionTypes/SectionBreakType.vue' |
92 | 92 | import FlowFormTextType from './QuestionTypes/TextType.vue' |
93 | 93 | import FlowFormUrlType from './QuestionTypes/UrlType.vue' |
| 94 | + import { IsMobile } from '../mixins/IsMobile' |
94 | 95 |
|
95 | 96 | export default { |
96 | 97 | name: 'FlowFormQuestion', |
|
119 | 120 | default: false |
120 | 121 | } |
121 | 122 | }, |
| 123 | + mixins: [ |
| 124 | + IsMobile |
| 125 | + ], |
122 | 126 | data() { |
123 | 127 | return { |
124 | 128 | QuestionType: QuestionType, |
|
129 | 133 | this.focusField() |
130 | 134 | this.dataValue = this.question.answer |
131 | 135 |
|
132 | | - this.$refs.qinner.addEventListener('transitionend', this.onTransitionEnd) |
| 136 | + this.$refs.qanimate.addEventListener('animationend', this.onAnimationEnd) |
133 | 137 | }, |
134 | 138 | beforeDestroy() { |
135 | | - this.$refs.qinner.removeEventListener('transitionend', this.onTransitionEnd) |
| 139 | + this.$refs.qanimate.removeEventListener('animationend', this.onAnimationEnd) |
136 | 140 | }, |
137 | 141 | methods: { |
138 | 142 | /** |
139 | 143 | * Autofocus the input box of the current question |
140 | 144 | */ |
141 | 145 | focusField() { |
142 | | - let el = this.$refs.questionComponent |
| 146 | + const el = this.$refs.questionComponent |
143 | 147 | |
144 | 148 | el && el.focus() |
145 | 149 | }, |
146 | 150 |
|
147 | | - onTransitionEnd() { |
148 | | - this.enterPressed = false |
| 151 | + onAnimationEnd() { |
| 152 | + this.focusField() |
149 | 153 | }, |
150 | 154 |
|
151 | 155 | /** |
152 | 156 | * Emits "answer" event and calls "onEnter" method on Enter press |
153 | 157 | */ |
154 | | - onEnter() { |
| 158 | + onEnter($event) { |
155 | 159 | const q = this.$refs.questionComponent |
156 | 160 |
|
157 | 161 | if (q) { |
158 | | - this.$emit('answer', q) |
| 162 | + if (!q.focused) { |
| 163 | + this.$emit('answer', q) |
| 164 | + } |
159 | 165 | q.onEnter() |
160 | 166 | } |
161 | 167 | }, |
|
0 commit comments