@eturnity/eturnity_reusable_components 7.24.2 → 7.24.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,97 @@
1
+ export default {
2
+ props: {
3
+ rules: {
4
+ type: Array,
5
+ required: false,
6
+ default: () => []
7
+ }
8
+ },
9
+ data() {
10
+ return {
11
+ error: false,
12
+ errMessage: ''
13
+ }
14
+ },
15
+ methods: {
16
+ validateInput(value) {
17
+ this.resetError()
18
+
19
+ this.rules.forEach((rule) => {
20
+ switch (rule) {
21
+ case 'required':
22
+ if (value) {
23
+ this.error = true
24
+ this.errMessage = this.$gettext('Required field')
25
+ }
26
+ break
27
+ case 'number':
28
+ this.checkNumber(value)
29
+ break
30
+ case 'string':
31
+ this.checkString(value)
32
+ break
33
+ case 'email':
34
+ this.checkEmail(value)
35
+ break
36
+ case 'phone':
37
+ this.checkPhone(value)
38
+ break
39
+ case 'year':
40
+ this.checkYear(value)
41
+ break
42
+ }
43
+ })
44
+ this.$emit('is-valid', !this.error)
45
+ },
46
+
47
+ resetError() {
48
+ this.error = false
49
+ this.errMessage = ''
50
+ },
51
+
52
+ checkNumber(value) {
53
+ this.resetError()
54
+
55
+ if (value && isNaN(value)) {
56
+ this.error = true
57
+ this.errMessage = this.$gettext('invalid_number')
58
+ }
59
+ },
60
+
61
+ checkString(value) {
62
+ this.resetError()
63
+
64
+ if (value && value.length < 3) {
65
+ this.error = true
66
+ this.errMessage = this.$gettext('invalid_string')
67
+ }
68
+ },
69
+
70
+ checkEmail(value) {
71
+ this.resetError()
72
+
73
+ if (value && !value.includes('@')) {
74
+ this.error = true
75
+ this.errMessage = this.$gettext('Invalid email address')
76
+ }
77
+ },
78
+
79
+ checkPhone(value) {
80
+ this.resetError()
81
+
82
+ if (value && !/^\d{10}$/.test(value)) {
83
+ this.error = true
84
+ this.errMessage = this.$gettext('invalid_phone')
85
+ }
86
+ },
87
+
88
+ checkYear(value) {
89
+ this.resetError()
90
+
91
+ if (value && (isNaN(value) || value < 1900 || value > 2100)) {
92
+ this.error = true
93
+ this.errMessage = this.$gettext('invalid_year')
94
+ }
95
+ }
96
+ }
97
+ }