@afeefa/vue-app 0.0.136 → 0.0.138
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.
|
1
|
+
0.0.138
|
package/package.json
CHANGED
@@ -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
|
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',
|
83
|
-
this.
|
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.
|
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,34 +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
|
-
} else {
|
125
|
-
if (!value) {
|
126
|
-
value = this.emptyValue
|
127
|
-
}
|
128
|
-
}
|
129
|
-
return value
|
130
|
-
}
|
131
|
-
|
132
|
-
get type () {
|
133
|
-
return this.$attrs.type || 'text'
|
134
|
-
}
|
135
|
-
|
136
|
-
get treatAsNumericValue () {
|
137
|
-
return this.type === 'number' || this.number
|
138
|
-
}
|
139
|
-
|
140
126
|
validate () {
|
127
|
+
const value = this.textFieldValueToModelValue()
|
141
128
|
const rules = this.validationRules
|
142
129
|
let errorMessage = null
|
143
130
|
for (const rule of rules) {
|
144
|
-
const value = this.stringToNumber(this.internalValue)
|
145
131
|
const result = rule(value)
|
146
132
|
if (result !== true) {
|
147
133
|
errorMessage = result
|
@@ -159,6 +145,49 @@ export default class ATextField extends Mixins(ComponentWidthMixin) {
|
|
159
145
|
this.setFocus()
|
160
146
|
}
|
161
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
|
+
|
162
191
|
setFocus (force = false) {
|
163
192
|
const focus = this.focus || force // set focus if this.focus or else if forced from outside
|
164
193
|
if (focus) {
|
@@ -190,9 +219,9 @@ export default class ATextField extends Mixins(ComponentWidthMixin) {
|
|
190
219
|
return this.validator.getMaxValueLength()
|
191
220
|
}
|
192
221
|
|
193
|
-
get
|
222
|
+
get emptyModelValue () {
|
194
223
|
if (this.validator) {
|
195
|
-
return this.
|
224
|
+
return this.getSanitizedValue('')
|
196
225
|
}
|
197
226
|
return null
|
198
227
|
}
|