@afeefa/vue-app 0.0.80 → 0.0.82

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.
@@ -1 +1 @@
1
- 0.0.80
1
+ 0.0.82
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afeefa/vue-app",
3
- "version": "0.0.80",
3
+ "version": "0.0.82",
4
4
  "description": "",
5
5
  "author": "Afeefa Kollektiv <kollektiv@afeefa.de>",
6
6
  "license": "MIT",
@@ -7,15 +7,17 @@
7
7
  min-width="auto"
8
8
  >
9
9
  <template #activator="{ on, attrs }">
10
- <v-combobox
10
+ <v-text-field
11
11
  ref="input"
12
12
  :value="formattedDate"
13
13
  :label="label"
14
14
  :style="cwm_widthStyle"
15
- readonly
16
15
  v-bind="{...$attrs, ...attrs}"
17
16
  :rules="validationRules"
17
+ :error-messages="errorMessages"
18
+ :readonly="type === 'month'"
18
19
  v-on="on"
20
+ @input="dateInputChanged"
19
21
  @click:clear="clearDate"
20
22
  @click.native="on.click"
21
23
  />
@@ -44,6 +46,7 @@ import { ComponentWidthMixin } from './mixins/ComponentWidthMixin'
44
46
  export default class ADatePicker extends Mixins(ComponentWidthMixin) {
45
47
  value_ = null
46
48
  menu = false
49
+ errorMessages = []
47
50
 
48
51
  created () {
49
52
  if (this.value) {
@@ -56,6 +59,7 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin) {
56
59
  if (this.validator) {
57
60
  this.$refs.input.validate(true)
58
61
  }
62
+ this.$refs.input.validate(true)
59
63
  }
60
64
 
61
65
  @Watch('value')
@@ -63,6 +67,21 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin) {
63
67
  this.value_ = this.value
64
68
  }
65
69
 
70
+ @Watch('value_')
71
+ value_Changed () { // validate on any change
72
+ this.errorMessages = []
73
+ if (this.validator) {
74
+ const rules = this.validator.getRules(this.label)
75
+ for (const rule of rules) {
76
+ const message = rule(this.value_)
77
+ if (typeof message === 'string') {
78
+ this.errorMessages.push(message)
79
+ break
80
+ }
81
+ }
82
+ }
83
+ }
84
+
66
85
  get date () {
67
86
  return this.value_
68
87
  ? this.value_.toISOString().substr(0, this.type === 'month' ? 7 : 10)
@@ -78,9 +97,22 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin) {
78
97
  this.$emit('input', this.value_)
79
98
  }
80
99
 
100
+ isDate (value) {
101
+ return value && value.match(/^(3[01]|[12][0-9]|0?[1-9]).(1[012]|0?[1-9]).((?:19|20)\d{2})$/)
102
+ }
103
+
104
+ dateInputChanged (value) {
105
+ if (!value) {
106
+ this.dateChanged(null)
107
+ } else if (this.isDate(value)) {
108
+ const [day, month, year] = value.split('.')
109
+ this.dateChanged(new Date(year + '-' + month + '-' + day))
110
+ }
111
+ }
112
+
81
113
  dateChanged (date) {
82
114
  this.menu = false
83
- this.value_ = new Date(date)
115
+ this.value_ = date ? new Date(date) : null
84
116
  this.$emit('input', this.value_)
85
117
  }
86
118
 
@@ -97,7 +129,15 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin) {
97
129
  }
98
130
 
99
131
  get validationRules () {
100
- return (this.validator && this.validator.getRules(this.label)) || []
132
+ if (this.type !== 'month') {
133
+ const dateFormat = v => {
134
+ if (v && !this.isDate(v)) {
135
+ return 'Das Datum sollte das Format TT.MM.JJJJ haben.'
136
+ }
137
+ return true
138
+ }
139
+ return [dateFormat]
140
+ }
101
141
  }
102
142
  }
103
143
  </script>