naive-ui icon indicating copy to clipboard operation
naive-ui copied to clipboard

Custom components can manually trigger change triggers in forms (在自定义组件中调用表单校验的 triggers)

Open moreant opened this issue 3 years ago • 1 comments
trafficstars

This function solves the problem (这个功能解决的问题)

在自定义封装的富文本组件中,我希望能提供一个方法能在能在富文本的更新事件中同时触发 FormRules 的 trigger ,这样就不用在每一个富文本更新事件中执行 FormItem 的 validate 了

In the custom packaged rich text component, I hope to provide a method that can trigger the trigger of FormRules in the update event of rich text at the same time, so that there is no need to execute the validate of FormItem in each rich text update event

Expected API (期望的 API)

类似 AntDV 里的 Form 组件有 useInjectFormItemContext 这个方法 https://www.antdv.com/components/form-cn/#_3-x

Like the useInjectFormItemContext method of Ant Design Vue's form component https://www.antdv.com/components/form/#_3-x

moreant avatar Jul 18 '22 03:07 moreant

Will consider.

07akioni avatar Jul 19 '22 16:07 07akioni

翻了一下源码,发现可以调用 _mixins 的 useFormItem 中的 nTriggerFormBlur 的方法来触发表单的 triggers,甚至能用 mergedDisabledRef 来继承 From 的 disabled 属性。

就是这个方法好像不是 “公开” 的。

https://github.com/tusen-ai/naive-ui/blob/01362acfaba2fc83ea8299b986d0797ebc5838e3/src/_mixins/use-form-item.ts#L105-L109

moreant avatar Feb 15 '23 13:02 moreant

遇到了相同的问题,感觉只要公开的useFormItem这个api就能满足需求。

tracy2zhang avatar Jun 12 '23 09:06 tracy2zhang

可以使用inject('n-form-item', null) 解决

null523 avatar Nov 17 '23 08:11 null523

This issue does not have any recent activity. If you are still experiencing similar problems, open a new error, including a minimal copy of the problem

jahnli avatar Mar 12 '24 13:03 jahnli