fix(Form): may scroll to incorrect field after submitted (#8159)

This commit is contained in:
neverland 2021-02-14 19:34:36 +08:00 committed by GitHub
parent c6e65f4fd6
commit 8cbf153073
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -159,10 +159,10 @@ export default createComponent({
.then(() => {
emit('submit', values);
})
.catch((errors) => {
.catch((errors: FieldValidateError[]) => {
emit('failed', { values, errors });
if (props.scrollToError) {
if (props.scrollToError && errors[0].name) {
scrollToField(errors[0].name);
}
});

View File

@ -7,7 +7,8 @@ export const inBrowser = typeof window !== 'undefined';
// unknown type for Vue prop
export const UnknownProp = (null as unknown) as PropType<unknown>;
export type ComponentInstance = ComponentPublicInstance<any>;
// eslint-disable-next-line
export type ComponentInstance = ComponentPublicInstance<{}, any>;
export function isDef<T>(val: T): val is NonNullable<T> {
return val !== undefined && val !== null;