Skip to content

Commit ae92d24

Browse files
committed
insertClass method implemented as a mixin
1 parent 342ddb2 commit ae92d24

File tree

8 files changed

+43
-60
lines changed

8 files changed

+43
-60
lines changed

examples/questionnaire/Example.vue

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import FlowForm from '../../src/components/FlowForm.vue'
7272
import QuestionModel, { QuestionType, ChoiceOption } from '../../src/models/QuestionModel'
7373
import LanguageModel from '../../src/models/LanguageModel'
74+
import { InsertClass } from '../../src/mixins/InsertClass'
7475
// If using the npm package, use the following line instead of the ones above.
7576
// import FlowForm, { QuestionModel, QuestionType, ChoiceOption, LanguageModel } from '@ditdot-dev/vue-flow-form'
7677
@@ -79,6 +80,9 @@
7980
components: {
8081
FlowForm
8182
},
83+
mixins: [
84+
InsertClass
85+
],
8286
data() {
8387
return {
8488
submitted: false,
@@ -290,20 +294,6 @@
290294
})
291295
292296
return data
293-
},
294-
295-
/**
296-
* Inserts new class into the language model string
297-
*/
298-
insertClass(value) {
299-
if (!value) return ''
300-
let stringArr = value.toString().split(" ")
301-
for (let i=0; i < stringArr.length; i++){
302-
if (stringArr[i][0]=== ":" && stringArr[i].length > 1){
303-
stringArr[i] = '<span class="f-language-key">' + stringArr[i].substring(1) + '</span>'
304-
}
305-
}
306-
return stringArr.join(" ")
307297
}
308298
},
309299
}

examples/quiz/Example.vue

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import FlowForm from '../../src/components/FlowForm.vue'
7171
import QuestionModel, { QuestionType, ChoiceOption} from '../../src/models/QuestionModel'
7272
import LanguageModel from '../../src/models/LanguageModel'
73+
import { InsertClass } from '../../src/mixins/InsertClass'
7374
// If using the npm package, use the following line instead of the ones above.
7475
// import FlowForm, { QuestionModel, QuestionType, ChoiceOption, LanguageModel } from '@ditdot-dev/vue-flow-form'
7576
@@ -78,6 +79,9 @@
7879
components: {
7980
FlowForm
8081
},
82+
mixins: [
83+
InsertClass
84+
],
8185
data() {
8286
return {
8387
submitted: false,
@@ -331,20 +335,6 @@
331335
332336
this.submitted = true
333337
this.calculateScore()
334-
},
335-
336-
/**
337-
* Inserts new class into the language model string
338-
*/
339-
insertClass(value) {
340-
if (!value) return ''
341-
let stringArr = value.toString().split(" ")
342-
for (let i=0; i < stringArr.length; i++){
343-
if (stringArr[i][0]=== ":" && stringArr[i].length > 1){
344-
stringArr[i] = '<span class="f-language-key">' + stringArr[i].substring(1) + '</span>'
345-
}
346-
}
347-
return stringArr.join(" ")
348338
}
349339
},
350340
}

src/assets/css/common.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ span.f-sub {
402402
margin-top: 6px;
403403
}
404404

405-
span.f-sub span{
405+
span.f-sub span:not(.f-language-key) {
406406
margin-right: .4rem;
407407
}
408408

src/components/FlowForm.vue

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
126126
import FlowFormQuestion from './Question.vue'
127127
import LanguageModel from '../models/LanguageModel'
128+
import { InsertClass } from '../mixins/InsertClass'
128129
129130
export default {
130131
name: 'FlowForm',
@@ -138,6 +139,9 @@
138139
default: () => new LanguageModel()
139140
}
140141
},
142+
mixins: [
143+
InsertClass
144+
],
141145
data() {
142146
return {
143147
completed: false,
@@ -468,19 +472,6 @@
468472
blurFocus() {
469473
document.activeElement && document.activeElement.blur && document.activeElement.blur()
470474
},
471-
/**
472-
* Inserts new class into the language model string
473-
*/
474-
insertClass(value) {
475-
if (!value) return ''
476-
let stringArr = value.toString().split(" ")
477-
for (let i=0; i < stringArr.length; i++){
478-
if (stringArr[i][0] === ":" && stringArr[i].length > 1){
479-
stringArr[i] = '<span class="f-language-key">' + stringArr[i].substring(1) + '</span>'
480-
}
481-
}
482-
return stringArr.join(" ")
483-
},
484475
}
485476
}
486477
</script>

src/components/Question.vue

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<span class="f-sub" v-if="question.subtitle || question.type === QuestionType.LongText || question.multiple">
3232
<span v-if="question.subtitle">{{ question.subtitle }}</span>
3333

34-
<span class="f-help" v-if="question.type === QuestionType.LongText && !isMobile">{{ question.helpText || language.longTextHelpText }}</span>
34+
<span class="f-help" v-if="question.type === QuestionType.LongText && !isMobile" v-html="question.helpText || insertClass(language.longTextHelpText)"></span>
3535

3636
<span class="f-help" v-if="question.multiple">{{ question.helpText || language.multipleChoiceHelpText }}</span>
3737
</span>
@@ -96,6 +96,7 @@
9696
import FlowFormTextType from './QuestionTypes/TextType.vue'
9797
import FlowFormUrlType from './QuestionTypes/UrlType.vue'
9898
import { IsMobile } from '../mixins/IsMobile'
99+
import { InsertClass } from '../mixins/InsertClass'
99100
100101
export default {
101102
name: 'FlowFormQuestion',
@@ -125,7 +126,8 @@
125126
}
126127
},
127128
mixins: [
128-
IsMobile
129+
IsMobile,
130+
InsertClass
129131
],
130132
data() {
131133
return {
@@ -224,19 +226,6 @@
224226
}
225227
226228
return q.showInvalid()
227-
},
228-
/**
229-
* Inserts new class into the language model string
230-
*/
231-
insertClass(value) {
232-
if (!value) return ''
233-
let stringArr = value.toString().split(" ")
234-
for (let i=0; i < stringArr.length; i++){
235-
if (stringArr[i][0] === ":" && stringArr[i].length > 1){
236-
stringArr[i] = '<span class="f-language-key">' + stringArr[i].substring(1) + '</span>'
237-
}
238-
}
239-
return stringArr.join(" ")
240229
}
241230
},
242231
computed: {

src/components/QuestionTypes/BaseType.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import QuestionModel, { QuestionType } from '../../models/QuestionModel'
1111
import LanguageModel from '../../models/LanguageModel'
1212
import { IsMobile } from '../../mixins/IsMobile'
13+
import { InsertClass } from '../../mixins/InsertClass'
1314
1415
export default {
1516
name: 'FlowFormBaseType',
@@ -20,7 +21,8 @@
2021
value: [String, Array]
2122
},
2223
mixins: [
23-
IsMobile
24+
IsMobile,
25+
InsertClass
2426
],
2527
data() {
2628
return {

src/mixins/InsertClass.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright (c) 2020 - present, DITDOT Ltd. - MIT Licence
3+
https://github.com/ditdot-dev/vue-flow-form
4+
https://www.ditdot.hr/en
5+
*/
6+
7+
// Mixin that inserts a new CSS class into the language model string to format the :key
8+
export const InsertClass = {
9+
methods: {
10+
insertClass(value) {
11+
if (!value) return ''
12+
let stringArr = value.toString().split(" ")
13+
for (let i = 0; i < stringArr.length; i++) {
14+
if (stringArr[i].slice(0,4) === ":key") {
15+
stringArr[i] = '<span class="f-language-key">' + stringArr[i].substring(5, stringArr[i].length - 1) + '</span>'
16+
}
17+
}
18+
return stringArr.join(" ")
19+
}
20+
}
21+
}

src/models/LanguageModel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ export default class LanguageModel {
1010
constructor(options) {
1111
this.ok = 'OK'
1212
this.continue = 'Continue'
13-
this.pressEnter = 'Press :enter'
13+
this.pressEnter = 'Press :key(Enter)';
1414
this.multipleChoiceHelpText = 'Choose as many as you like'
1515
this.otherPrompt = 'Other'
1616
this.placeholder = 'Type your answer here...'
1717
this.submitText = 'Submit'
18-
this.longTextHelpText = 'SHIFT + ENTER to make a line break.'
18+
this.longTextHelpText = ':key(Shift) + :key(Enter) to make a line break.'
1919
this.prev = 'Prev'
2020
this.next = 'Next'
2121
this.percentCompleted = ':percent% completed'

0 commit comments

Comments
 (0)