@afeefa/vue-app 0.0.135 → 0.0.137

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- 0.0.135
1
+ 0.0.137
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afeefa/vue-app",
3
- "version": "0.0.135",
3
+ "version": "0.0.137",
4
4
  "description": "",
5
5
  "author": "Afeefa Kollektiv <kollektiv@afeefa.de>",
6
6
  "license": "MIT",
@@ -75,7 +75,7 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin, UsesPositio
75
75
  }
76
76
 
77
77
  get clearable () {
78
- if (this.validator && this.validator.param('null') === false) {
78
+ if (this.validator && this.validator.getParam('filled')) {
79
79
  return false
80
80
  }
81
81
  return true
@@ -235,7 +235,7 @@ export default class ARichTextArea extends Vue {
235
235
  if (!this.validator) {
236
236
  return false
237
237
  }
238
- return this.validator.getParams().max || false
238
+ return this.validator.getParam('max') || false
239
239
  }
240
240
 
241
241
  get currentValueStripped () {
@@ -31,7 +31,7 @@ export default class ATextArea extends Vue {
31
31
  if (!this.validator) {
32
32
  return false
33
33
  }
34
- return this.validator.getParams().max || false
34
+ return this.validator.getParam('max') || false
35
35
  }
36
36
  }
37
37
  </script>
@@ -9,6 +9,7 @@
9
9
  @input="inputChanged"
10
10
  @keyup.esc="clear"
11
11
  @click:clear="clear"
12
+ @blur="sanitizeInternalValue"
12
13
  v-on="listeners"
13
14
  />
14
15
  </template>
@@ -54,12 +55,17 @@ export default class ATextField extends Mixins(ComponentWidthMixin) {
54
55
 
55
56
  @Watch('value')
56
57
  valueChanged () {
58
+ const value = this.textFieldValueToModelValue()
59
+ if (value === this.value) {
60
+ // return if sanitized textfield value === model value
61
+ return
62
+ }
57
63
  this.setInternalValue(this.value)
58
64
  }
59
65
 
60
66
  get listeners () {
61
- // remove input from nested listening
62
- // let clients listend to only THIS component
67
+ // remove @input from nested listening
68
+ // let clients listen to only THIS component
63
69
  const listeners = {...this.$listeners}
64
70
  delete listeners.input
65
71
  return listeners
@@ -76,11 +82,15 @@ export default class ATextField extends Mixins(ComponentWidthMixin) {
76
82
  return attrs
77
83
  }
78
84
 
79
- clear () {
85
+ clear (event) {
80
86
  if (this.clearable) {
87
+ // empty value if value exists
88
+ if (this.internalValue) {
89
+ event.stopPropagation()
90
+ }
81
91
  this.setInternalValue('')
82
- this.$emit('input', this.emptyValue)
83
- this.validate()
92
+ this.$emit('input:internal', '')
93
+ this.$emit('input', this.emptyModelValue)
84
94
  this.$emit('clear')
85
95
  }
86
96
  }
@@ -89,12 +99,11 @@ export default class ATextField extends Mixins(ComponentWidthMixin) {
89
99
  this.$emit('input:internal', this.internalValue)
90
100
 
91
101
  const valid = this.validate()
92
-
93
102
  if (!valid) {
94
103
  return
95
104
  }
96
105
 
97
- const value = this.stringToNumber(this.internalValue)
106
+ const value = this.textFieldValueToModelValue()
98
107
 
99
108
  // NaN means: wrong numerical value AND no validator present
100
109
  // otherwise validator would return validate() -> false
@@ -114,30 +123,11 @@ export default class ATextField extends Mixins(ComponentWidthMixin) {
114
123
  }
115
124
  }
116
125
 
117
- stringToNumber (value) {
118
- if (this.treatAsNumericValue) {
119
- if (!value) {
120
- value = null
121
- } else {
122
- value = this.internalValue.match(/^-?\d*(\.\d+)?$/) ? parseFloat(this.internalValue) : NaN
123
- }
124
- }
125
- return value
126
- }
127
-
128
- get type () {
129
- return this.$attrs.type || 'text'
130
- }
131
-
132
- get treatAsNumericValue () {
133
- return this.type === 'number' || this.number
134
- }
135
-
136
126
  validate () {
127
+ const value = this.textFieldValueToModelValue()
137
128
  const rules = this.validationRules
138
129
  let errorMessage = null
139
130
  for (const rule of rules) {
140
- const value = this.stringToNumber(this.internalValue)
141
131
  const result = rule(value)
142
132
  if (result !== true) {
143
133
  errorMessage = result
@@ -155,6 +145,49 @@ export default class ATextField extends Mixins(ComponentWidthMixin) {
155
145
  this.setFocus()
156
146
  }
157
147
 
148
+ sanitizeInternalValue () {
149
+ const sanitizedValue = this.getSanitizedInternalValue()
150
+ this.setInternalValue(sanitizedValue)
151
+ }
152
+
153
+ getSanitizedInternalValue () {
154
+ return this.getSanitizedValue(this.internalValue)
155
+ }
156
+
157
+ getSanitizedValue (value) {
158
+ if (this.validator) {
159
+ const sanitizers = this.validator.getSanitizers()
160
+ for (const sanitizer of sanitizers) {
161
+ value = sanitizer(value)
162
+ }
163
+ }
164
+ return value
165
+ }
166
+
167
+ textFieldValueToModelValue () {
168
+ const sanitizedValue = this.getSanitizedInternalValue()
169
+ return this.stringToNumber(sanitizedValue)
170
+ }
171
+
172
+ stringToNumber (value) {
173
+ const textFieldType = this.$attrs.type || 'text'
174
+ const treatAsNumericValue = textFieldType === 'number' || this.number
175
+
176
+ if (treatAsNumericValue) {
177
+ if (!value) {
178
+ value = null
179
+ } else {
180
+ value = this.internalValue.match(/^-?\d*(\.\d+)?$/) ? parseFloat(this.internalValue) : NaN
181
+ }
182
+ } else {
183
+ if (!value) {
184
+ value = this.emptyModelValue
185
+ }
186
+ }
187
+
188
+ return value
189
+ }
190
+
158
191
  setFocus (force = false) {
159
192
  const focus = this.focus || force // set focus if this.focus or else if forced from outside
160
193
  if (focus) {
@@ -186,9 +219,9 @@ export default class ATextField extends Mixins(ComponentWidthMixin) {
186
219
  return this.validator.getMaxValueLength()
187
220
  }
188
221
 
189
- get emptyValue () {
222
+ get emptyModelValue () {
190
223
  if (this.validator) {
191
- return this.validator.getEmptyValue()
224
+ return this.getSanitizedValue('')
192
225
  }
193
226
  return null
194
227
  }
@@ -64,7 +64,7 @@ export class FormFieldMixin extends Vue {
64
64
 
65
65
  const options = []
66
66
 
67
- if (!this.validator || !this.validator.getParams().filled) {
67
+ if (!this.validator || !this.validator.getParam('filled')) {
68
68
  options.push({
69
69
  itemText: 'Keine Auswahl',
70
70
  itemValue: null
@@ -252,6 +252,7 @@ export default class App extends Vue {
252
252
  width: 100%;
253
253
  left: 0;
254
254
  top: 0;
255
+ height:40px;
255
256
  padding: .2rem 1.1rem;
256
257
  background-color: white;
257
258
  }