1+ // Create and setup your form here
2+
3+ <template >
4+ <div >
5+
6+ <flow-form
7+ ref =" flowform"
8+ v-on:complete =" onComplete"
9+ v-on:submit =" onSubmit"
10+ v-bind:questions =" questions"
11+ v-bind:language =" language"
12+ v-bind:progressbar =" false"
13+ >
14+ <!-- Custom content for the Complete/Submit screen slots in the FlowForm component -->
15+ <!-- We've overriden the default "complete" slot content -->
16+ <template v-slot :complete >
17+ <div class =" section-wrap" >
18+ <p >
19+ <span class =" fh2" >Thank you for visiting our technical support page. 🙏</span >
20+ <span class =" section-text" >
21+ Have a great day!
22+ </span >
23+ </p >
24+ </div >
25+ </template >
26+
27+ <!-- We've overriden the default "completeButton" slot content -->
28+ <template v-slot :completeButton >
29+ <div class =" f-submit" v-if =" !submitted" >
30+ <!-- Leave empty to hide default submit button -->
31+ </div >
32+ </template >
33+ </flow-form >
34+ </div >
35+ </template >
36+
37+ <script >
38+ /*
39+ Copyright (c) 2020 - present, DITDOT Ltd. - MIT Licence
40+ https://www.ditdot.hr/en
41+ */
42+
43+ // Import necessary components and classes
44+ import FlowForm from ' ../../src/components/FlowForm.vue'
45+ import QuestionModel , { QuestionType , ChoiceOption , LinkOption } from ' ../../src/models/QuestionModel'
46+ import LanguageModel from ' ../../src/models/LanguageModel'
47+ // If using the npm package, use the following line instead of the ones above.
48+ // import FlowForm, { QuestionModel, QuestionType, ChoiceOption, LanguageModel } from '@ditdot-dev/vue-flow-form'
49+
50+ export default {
51+ name: ' example' ,
52+ components: {
53+ FlowForm
54+ },
55+ data () {
56+ return {
57+ submitted: false ,
58+ completed: false ,
59+ language: new LanguageModel (),
60+ // Create question list with QuestionModel instances
61+ questions: [
62+ new QuestionModel ({
63+ id: ' multiple_choice' ,
64+ tagline: " Welcome to our support page!" ,
65+ title: ' Hi 👋, how can we help you today?' ,
66+ type: QuestionType .MultipleChoice ,
67+ multiple: false ,
68+ required: true ,
69+ helpTextShow: false ,
70+ options: [
71+ new ChoiceOption ({
72+ label: ' I have a technical issue' ,
73+ value: ' technical_issue'
74+ }),
75+ new ChoiceOption ({
76+ label: ' I wish to check my ticket status' ,
77+ value: ' enter_ticket'
78+ }),
79+ ],
80+ jump: {
81+ technical_issue: ' technical_issue' ,
82+ enter_ticket: ' enter_ticket'
83+ }
84+ }),
85+ new QuestionModel ({
86+ id: ' technical_issue' ,
87+ tagline: ' Submit issue > Step 1/3' ,
88+ title: ' Have you read our technical FAQ?' ,
89+ type: QuestionType .MultipleChoice ,
90+ multiple: false ,
91+ required: true ,
92+ helpTextShow: false ,
93+ description: " Here you'll find answers to" ,
94+ descriptionLink: [
95+ new LinkOption ({
96+ url: ' #' ,
97+ text: ' FAQs' ,
98+ target: ' _self'
99+ })
100+ ],
101+ options: [
102+ new ChoiceOption ({
103+ label: ' Yes, but still couldn’t find the answer.' ,
104+ value: ' faq_no'
105+ }),
106+ ],
107+ jump: {
108+ faq_no: ' faq_no'
109+ }
110+ }),
111+ new QuestionModel ({
112+ id: ' enter_ticket' ,
113+ tagline: ' Support page > Ticket status' ,
114+ title: ' Please enter your 6-digit code' ,
115+ subtitle: ' You received this when you reported your problem' ,
116+ type: QuestionType .Number ,
117+ multiple: false ,
118+ required: true ,
119+ mask: ' #-#-#-#-#-#' ,
120+ placeholder: ' #-#-#-#-#-#'
121+ }),
122+ new QuestionModel ({
123+ id: ' ticket_status' ,
124+ tagline: ' Support page > Ticket status' ,
125+ title: ' Good news - the wheels are turning, your ticket is being processed!😉' ,
126+ type: QuestionType .SectionBreak ,
127+ jump: {
128+ _other: ' _submit'
129+ }
130+ }),
131+ new QuestionModel ({
132+ id: ' faq_no' ,
133+ tagline: ' Submit issue > Step 2/3' ,
134+ title: ' Please describe your problem' ,
135+ type: QuestionType .LongText ,
136+ required: true ,
137+ placeholder: ' Start typing here...' ,
138+ }),
139+ new QuestionModel ({
140+ id: ' ticket' ,
141+ tagline: ' Submit issue > Step 3/3' ,
142+ title: ' Your ticket number is: ' + this .getTicket (),
143+ description: ' Thank You. Our support team will contact you as soon as possible.' ,
144+ type: QuestionType .SectionBreak ,
145+ jump: {
146+ _other: ' _submit'
147+ }
148+ })
149+ ]
150+ }
151+ },
152+ mounted () {
153+ document .addEventListener (' keyup' , this .onKeyListener )
154+ },
155+ beforeDestroy () {
156+ document .removeEventListener (' keyup' , this .onKeyListener )
157+ },
158+ methods: {
159+ onKeyListener ($event ) {
160+ // We've overriden the default "complete" slot so
161+ // we need to implement the "keyup" listener manually.
162+
163+ if ($event .key === ' Enter' && this .completed && ! this .submitted ) {
164+ this .onSendData ()
165+ }
166+ },
167+
168+ /* eslint-disable-next-line no-unused-vars */
169+ onComplete (completed , questionList ) {
170+ // This method is called whenever the "completed" status is changed.
171+ this .completed = completed
172+ },
173+
174+ /* eslint-disable-next-line no-unused-vars */
175+ onSubmit (questionList ) {
176+ // This method will only be called if you don't override the
177+ // completeButton slot.
178+ this .onSendData ()
179+ },
180+
181+ onSendData () {
182+ // Set `submitted` to true so the form knows not to allow back/forward
183+ // navigation anymore.
184+ this .$refs .flowform .submitted = true
185+
186+ this .submitted = true
187+
188+ /* eslint-disable-next-line no-unused-vars */
189+ const data = this .getData ()
190+ /*
191+ You can use Fetch API to send the data to your server, eg.:
192+
193+ fetch(url, {
194+ method: 'POST',
195+ headers: {
196+ 'Content-Type': 'application/json'
197+ },
198+ body: JSON.stringify(data)
199+ })
200+ */
201+ },
202+
203+ getData () {
204+ const data = {
205+ questions: [],
206+ answers: []
207+ }
208+
209+ this .questions .forEach (question => {
210+ if (question .title ) {
211+ let answer = question .answer
212+ if (typeof answer === ' object' ) {
213+ answer = answer .join (' , ' )
214+ }
215+
216+ data .questions .push (question .title )
217+ data .answers .push (answer)
218+ }
219+ })
220+
221+ return data
222+ },
223+
224+ getTicket () {
225+ const ticket = Math .floor (Math .random () * (999999 - 100000 ) + 100000 ).toString ();
226+ return ticket
227+ }
228+ }
229+ }
230+ </script >
231+
232+ <style lang="css">
233+ @import ' ../../src/assets/css/themes/theme-green.css' ;
234+ /* If using the npm package, use the following lines instead of the one above */
235+ /* @import '~@ditdot-dev/vue-flow-form/dist/vue-flow-form.css'; */
236+ /* @import '~@ditdot-dev/vue-flow-form/dist/vue-flow-form.theme-green.css'; */
237+ </style >
0 commit comments