Skip to content

Commit a58a84b

Browse files
committed
feat: new field binding object
1 parent f6dc057 commit a58a84b

1 file changed

Lines changed: 9 additions & 41 deletions

File tree

packages/core/src/Provider.ts

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ref, computed, SetupContext, inject } from 'vue';
22
import { normalizeRules } from './utils/rules';
33
import { normalizeChildren } from './utils/vnode';
4-
import { isNullOrUndefined } from './utils';
54
import { getConfig } from './config';
65
import { RuleContainer } from './extend';
76
import { Flag, ValidationFlags, FormController } from './types';
@@ -68,9 +67,6 @@ export const ValidationProvider: any = {
6867
}
6968
);
7069

71-
// let initialValue: any;
72-
// eslint-disable-next-line prefer-const
73-
// let initialized = false;
7470
const id = '';
7571
const resolvedRules = {};
7672

@@ -95,50 +91,23 @@ export const ValidationProvider: any = {
9591
return isRequired;
9692
});
9793

98-
const classes = computed(() => {
99-
const names = getConfig().classes;
100-
const acc: Record<string, boolean> = {};
101-
const keys = Object.keys(flags);
102-
const length = keys.length;
103-
104-
for (let i = 0; i < length; i++) {
105-
const flag = keys[i];
106-
const className = (names && names[flag]) || flag;
107-
const value = flags[flag as Flag].value;
108-
if (isNullOrUndefined(value)) {
109-
continue;
110-
}
111-
112-
if ((flag === 'valid' || flag === 'invalid') && !flags.validated) {
113-
continue;
114-
}
115-
116-
if (typeof className === 'string') {
117-
acc[className] = value;
118-
} else if (Array.isArray(className)) {
119-
className.forEach(cls => {
120-
acc[cls] = value;
121-
});
122-
}
123-
}
124-
125-
return acc;
126-
});
127-
12894
const slotProps = computed(() => {
12995
return {
96+
field: {
97+
'aria-invalid': flags.invalid ? 'true' : 'false',
98+
'aria-required': isRequired.value ? 'true' : 'false',
99+
'aria-errormessage': `vee_${id}`,
100+
onInput: handleChange,
101+
onChange: handleChange,
102+
'onUpdate:modelValue': handleChange,
103+
onBlur: onBlur
104+
},
130105
flags: unwrappedFlags.value,
131106
errors: errors.value,
132-
classes: classes.value,
133107
failedRules: failedRules.value,
134108
reset,
135109
validate: validateField,
136110
handleChange,
137-
ariaInput: {
138-
'aria-invalid': flags.invalid ? 'true' : 'false',
139-
'aria-required': isRequired.value ? 'true' : 'false',
140-
'aria-errormessage': `vee_${id}`
141-
},
142111
ariaMsg: {
143112
id: `vee_${id}`,
144113
'aria-live': errors.value.length ? 'assertive' : 'off'
@@ -147,7 +116,6 @@ export const ValidationProvider: any = {
147116
});
148117

149118
return () => {
150-
// updateRenderingContextRefs();
151119
const children = normalizeChildren(ctx, slotProps.value);
152120

153121
return children;

0 commit comments

Comments
 (0)