|
6 | 6 | <flow-form |
7 | 7 | ref="flowform" |
8 | 8 | v-on:complete="onComplete" |
9 | | - v-bind:questions="questions" |
10 | 9 | v-bind:language="language" |
11 | 10 | v-bind:progressbar="false" |
12 | 11 | v-bind:standalone="true" |
13 | 12 | > |
| 13 | + <question |
| 14 | + v-for="(question, index) in questions" |
| 15 | + v-bind="question" |
| 16 | + v-bind:key="'m' + index" |
| 17 | + v-model="question.model" |
| 18 | + > |
| 19 | + </question> |
| 20 | + |
14 | 21 | <!-- Custom content for the Complete/Submit screen slots in the FlowForm component --> |
15 | | - <!-- We've overriden the default "complete" slot content --> |
16 | 22 | <template v-slot:complete> |
17 | 23 | <div class="f-section-wrap"> |
18 | | - <div v-if="questions[0].answer === 'technical_issue'"> |
| 24 | + <div v-if="questions[0].model === 'technical_issue'"> |
19 | 25 | <span class="f-tagline">Submit issue > Step 3/3</span> |
20 | 26 | <div v-if="loading"> |
21 | 27 | <span class="fh2">Please wait, submitting...</span> |
|
27 | 33 | </div> |
28 | 34 | <div v-else> |
29 | 35 | <span class="f-tagline">Support page > Ticket status</span> |
30 | | - <span class="fh2">Good news - the wheels are turning, your ticket is being processed!😉</span> |
31 | | - <p class="f-description"><span>Have a great day!</span></p> |
| 36 | + <div v-if="loading"> |
| 37 | + <span class="fh2">Please wait, checking...</span> |
| 38 | + </div> |
| 39 | + <div v-else> |
| 40 | + <span class="fh2">Good news - the wheels are turning, your ticket No. {{ formatTicket(questions[2].model) }} is being processed!😉</span> |
| 41 | + <p class="f-description"><span>Have a great day!</span></p> |
| 42 | + </div> |
32 | 43 | </div> |
33 | 44 | </div> |
34 | 45 | </template> |
35 | | - |
36 | | - <!-- We've overriden the default "completeButton" slot content --> |
| 46 | + <!-- We've overriden the default "complete" slot content --> |
37 | 47 | <template v-slot:completeButton> |
38 | 48 | <div class="f-submit"> |
39 | 49 | <!-- Leave empty to hide default submit button --> |
|
51 | 61 |
|
52 | 62 | // Import necessary components and classes |
53 | 63 | import FlowForm from '../../src/components/FlowForm.vue' |
54 | | - import QuestionModel, { QuestionType, ChoiceOption, LinkOption } from '../../src/models/QuestionModel' |
| 64 | + import Question from '../../src/components/Question.vue' |
55 | 65 | import LanguageModel from '../../src/models/LanguageModel' |
56 | 66 | // If using the npm package, use the following line instead of the ones above. |
57 | | - // import FlowForm, { QuestionModel, QuestionType, ChoiceOption, LinkOption, LanguageModel } from '@ditdot-dev/vue-flow-form' |
| 67 | + // import FlowForm, Question, { LanguageModel } from '@ditdot-dev/vue-flow-form' |
58 | 68 |
|
59 | 69 | export default { |
60 | 70 | name: 'example', |
61 | 71 | components: { |
62 | | - FlowForm |
| 72 | + FlowForm, |
| 73 | + Question |
63 | 74 | }, |
64 | 75 | data() { |
65 | 76 | return { |
66 | 77 | loading: false, |
67 | 78 | completed: false, |
68 | 79 | language: new LanguageModel(), |
69 | | - // Create question list with QuestionModel instances |
70 | 80 | questions: [ |
71 | | - new QuestionModel({ |
| 81 | + { |
| 82 | + type: 'multiplechoice', |
72 | 83 | id: 'multiple_choice', |
73 | | - tagline: "Welcome to our demo support page!", |
| 84 | + tagline: 'Welcome to our demo support page!', |
74 | 85 | title: 'Hi 👋, how can we help you today?', |
75 | | - type: QuestionType.MultipleChoice, |
76 | 86 | multiple: false, |
77 | 87 | required: true, |
78 | 88 | helpTextShow: false, |
79 | 89 | options: [ |
80 | | - new ChoiceOption({ |
| 90 | + { |
81 | 91 | label: 'I have a technical issue', |
82 | 92 | value: 'technical_issue' |
83 | | - }), |
84 | | - new ChoiceOption({ |
| 93 | + }, |
| 94 | + { |
85 | 95 | label: 'I wish to check my ticket status', |
86 | 96 | value: 'enter_ticket' |
87 | | - }), |
| 97 | + }, |
88 | 98 | ], |
89 | 99 | jump: { |
90 | 100 | technical_issue: 'technical_issue', |
91 | 101 | enter_ticket: 'enter_ticket' |
92 | | - } |
93 | | - }), |
94 | | - new QuestionModel({ |
| 102 | + }, |
| 103 | + model: '', |
| 104 | + }, |
| 105 | + { |
| 106 | + type: 'multiplechoice', |
95 | 107 | id: 'technical_issue', |
96 | 108 | tagline: 'Submit issue > Step 1/3', |
97 | 109 | title: 'Have you read our technical FAQ?', |
98 | | - type: QuestionType.MultipleChoice, |
99 | 110 | multiple: false, |
100 | 111 | required: true, |
101 | 112 | helpTextShow: false, |
102 | 113 | description: "Here you'll find answers to", |
103 | 114 | descriptionLink: [ |
104 | | - new LinkOption({ |
| 115 | + { |
105 | 116 | url: '#', |
106 | 117 | text: 'FAQs', |
107 | 118 | target: '_self' |
108 | | - }) |
| 119 | + } |
109 | 120 | ], |
110 | 121 | options: [ |
111 | | - new ChoiceOption({ |
| 122 | + { |
112 | 123 | label: 'Yes, but I couldn’t find the answer', |
113 | 124 | value: 'faq_no' |
114 | | - }), |
| 125 | + } |
115 | 126 | ], |
116 | 127 | jump: { |
117 | 128 | faq_no: 'faq_no' |
118 | | - } |
119 | | - }), |
120 | | - new QuestionModel({ |
| 129 | + }, |
| 130 | + model: '', |
| 131 | + }, |
| 132 | + { |
| 133 | + type: 'text', |
121 | 134 | id: 'enter_ticket', |
122 | 135 | tagline: 'Support page > Ticket status', |
123 | 136 | title: 'Please enter your 6-digit code.', |
124 | 137 | subtitle: 'You received this when you reported your problem.', |
125 | | - type: QuestionType.Text, |
126 | | - multiple: false, |
| 138 | + multiple: false, |
127 | 139 | required: true, |
128 | 140 | mask: '#-#-#-#-#-#', |
129 | 141 | placeholder: '#-#-#-#-#-#', |
130 | 142 | jump: { |
131 | 143 | _other: '_submit' |
132 | | - } |
133 | | - }), |
134 | | - new QuestionModel({ |
135 | | - id: 'faq_no', |
| 144 | + }, |
| 145 | + model: '' |
| 146 | + }, |
| 147 | + { |
| 148 | + type: 'longtext', |
| 149 | + id: "faq_no", |
136 | 150 | tagline: 'Submit issue > Step 2/3', |
137 | 151 | title: 'Please describe your problem.', |
138 | | - type: QuestionType.LongText, |
139 | 152 | required: true, |
140 | 153 | placeholder: 'Start typing here...', |
141 | | - }) |
| 154 | + model: '' |
| 155 | + } |
142 | 156 | ] |
143 | 157 | } |
144 | 158 | }, |
|
183 | 197 | questions: [], |
184 | 198 | answers: [] |
185 | 199 | } |
186 | | -
|
| 200 | + |
187 | 201 | this.questions.forEach(question => { |
188 | 202 | if (question.title) { |
189 | | - let answer = question.answer |
| 203 | + let answer = question.model |
190 | 204 | if (Array.isArray(answer)) { |
191 | 205 | answer = answer.join(', ') |
192 | 206 | } |
|
195 | 209 | data.answers.push(answer) |
196 | 210 | } |
197 | 211 | }) |
198 | | -
|
| 212 | + |
199 | 213 | return data |
200 | 214 | }, |
201 | 215 |
|
| 216 | + formatTicket(ticket) { |
| 217 | + return ticket && ticket.replace(/-/g, '') |
| 218 | + }, |
| 219 | +
|
202 | 220 | getTicket() { |
203 | 221 | return Math.floor(Math.random() * (999999 - 100000) + 100000).toString() |
204 | 222 | } |
|
0 commit comments