Skip to content

Commit 4914864

Browse files
committed
feat: export useInjectFormItemContext
1 parent 59e0985 commit 4914864

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

components/form/Form.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type {
2222
RuleError,
2323
ValidateErrorEntity,
2424
ValidateOptions,
25+
Callbacks,
2526
} from './interface';
2627
import { useInjectSize } from '../_util/hooks/useSize';
2728
import useConfigInject from '../_util/hooks/useConfigInject';
@@ -76,11 +77,13 @@ export const formProps = {
7677
// 提交失败自动滚动到第一个错误字段
7778
scrollToFirstError: { type: [Boolean, Object] as PropType<boolean | Options> },
7879
onSubmit: PropTypes.func,
79-
onFinish: PropTypes.func,
80-
onFinishFailed: PropTypes.func,
8180
name: PropTypes.string,
8281
validateTrigger: { type: [String, Array] as PropType<string | string[]> },
8382
size: { type: String as PropType<SizeType> },
83+
onValuesChange: { type: Function as PropType<Callbacks['onValuesChange']> },
84+
onFieldsChange: { type: Function as PropType<Callbacks['onFieldsChange']> },
85+
onFinish: { type: Function as PropType<Callbacks['onFinish']> },
86+
onFinishFailed: { type: Function as PropType<Callbacks['onFinishFailed']> },
8487
};
8588

8689
export type FormProps = Partial<ExtractPropTypes<typeof formProps>>;

components/form/FormItem.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,16 @@ export default defineComponent({
274274

275275
useProvideFormItemContext({
276276
id: fieldId,
277-
onFieldBlur,
278-
onFieldChange,
277+
onFieldBlur: () => {
278+
if (props.autoLink) {
279+
onFieldBlur();
280+
}
281+
},
282+
onFieldChange: () => {
283+
if (props.autoLink) {
284+
onFieldChange();
285+
}
286+
},
279287
clearValidate,
280288
});
281289
let registered = false;

components/form/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import Form, { formProps } from './Form';
33
import FormItem, { formItemProps } from './FormItem';
44
import useForm from './useForm';
55
import { useInjectFormItemContext } from './FormItemContext';
6+
export type { Rule, RuleObject } from './interface';
67

78
export type { FormProps } from './Form';
89
export type { FormItemProps } from './FormItem';
910

11+
Form.useInjectFormItemContext = useInjectFormItemContext;
1012
/* istanbul ignore next */
1113
Form.install = function (app: App) {
1214
app.component(Form.name, Form);

0 commit comments

Comments
 (0)