Skip to content

Commit f005874

Browse files
Jo-Byrjourdain
authored andcommitted
fix(textfield): validate on blur only
Remove update on update:modelValue to fix bug preventing typing non integer values in TextField Remove condition on dirty call in validate to replace the call in update Uniformize TextField template.html structure
1 parent fbc8509 commit f005874

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

vue3-components/src/widgets/TextField/script.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,30 +174,21 @@ export default {
174174
};
175175

176176
const validate = function validate(component = 0) {
177-
// console.log('validate', component, this.size);
178-
let isDirty = false;
179-
// let useInitial = false;
180177
const value = component ? model.value[component - 1] : model.value;
178+
const newValue = convert.value(value);
181179
if (Number(props.size) !== 1) {
182-
isDirty = model.value[component - 1] !== convert.value(value);
183-
model.value[component - 1] = convert.value(value);
184-
if (model.value[component - 1] === null) {
180+
model.value[component - 1] = newValue;
181+
if (newValue === null) {
185182
model.value[component - 1] = props.initial?.[component - 1];
186-
// useInitial = true;
187183
}
188184
model.value = model.value.slice();
189185
} else {
190-
isDirty = model.value !== convert.value(value);
191-
model.value = convert.value(value);
186+
model.value = newValue;
192187
if (model.value === null) {
193188
model.value = props.initial;
194-
// useInitial = true;
195189
}
196190
}
197-
// console.log('validate', component, isDirty, useInitial);
198-
if (isDirty) {
199-
dirty(props.name);
200-
}
191+
dirty(props.name);
201192
};
202193

203194
const refresh = function refresh() {
@@ -281,7 +272,6 @@ export default {
281272
};
282273

283274
const update = function update(component = 0) {
284-
// console.log('update', component, this.size);
285275
const value = component ? model.value[component - 1] : model.value;
286276
// must test against bool since it can be a string in case of error
287277
if (rule.value(value) === true) {

vue3-components/src/widgets/TextField/template.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
:name="`${data().type}:${name}:${i}`"
2121
:bg-color="color()"
2222
v-model="model"
23-
@update:modelValue="update()"
2423
:label="label"
2524
:hint="help"
2625
density="compact"
@@ -51,10 +50,9 @@
5150
:name="`${data().type}:${name}:${i}`"
5251
:bg-color="color(i)"
5352
v-model="model[i - 1]"
54-
@update:modelValue="update(i)"
5553
density="compact"
5654
:rules="[rule]"
57-
@update:focused="validate(i)"
55+
@blur="validate(i)"
5856
@keydown.enter="validate(i)"
5957
hide-details
6058
:disabled="disabled || !decorator.enable"

0 commit comments

Comments
 (0)