feat(form): `scrollToFirstError` supports passing in options (#3918)

pull/3923/head
John 4 years ago committed by GitHub
parent efb388cb05
commit d8628ce66a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,7 +10,7 @@ import { defaultValidateMessages } from './utils/messages';
import { allPromiseFinish } from './utils/asyncUtil';
import { toArray } from './utils/typeUtil';
import isEqual from 'lodash-es/isEqual';
import scrollIntoView from 'scroll-into-view-if-needed';
import scrollIntoView, { Options } from 'scroll-into-view-if-needed';
import initDefaultProps from '../_util/props-util/initDefaultProps';
import { tuple, VueNode } from '../_util/type';
import { ColProps } from '../grid/Col';
@ -56,7 +56,7 @@ export const formProps = {
validateMessages: PropTypes.object,
validateOnRuleChange: PropTypes.looseBool,
//
scrollToFirstError: PropTypes.looseBool,
scrollToFirstError: { type: [Boolean, Object] as PropType<boolean | Options> },
onSubmit: PropTypes.func,
onFinish: PropTypes.func,
onFinishFailed: PropTypes.func,
@ -151,7 +151,11 @@ const Form = defineComponent({
const { scrollToFirstError } = this;
this.$emit('finishFailed', errorInfo);
if (scrollToFirstError && errorInfo.errorFields.length) {
this.scrollToField(errorInfo.errorFields[0].name);
let scrollToFieldOptions: Options = {};
if (typeof scrollToFirstError === 'object') {
scrollToFieldOptions = scrollToFirstError;
}
this.scrollToField(errorInfo.errorFields[0].name, scrollToFieldOptions);
}
},
validate(...args: any[]) {

Loading…
Cancel
Save