naive-ui
naive-ui copied to clipboard
Custom components can manually trigger change triggers in forms (在自定义组件中调用表单校验的 triggers)
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
Will consider.
翻了一下源码,发现可以调用 _mixins 的 useFormItem 中的 nTriggerFormBlur 的方法来触发表单的 triggers,甚至能用 mergedDisabledRef 来继承 From 的 disabled 属性。
就是这个方法好像不是 “公开” 的。
https://github.com/tusen-ai/naive-ui/blob/01362acfaba2fc83ea8299b986d0797ebc5838e3/src/_mixins/use-form-item.ts#L105-L109
遇到了相同的问题,感觉只要公开的useFormItem这个api就能满足需求。
可以使用inject('n-form-item', null) 解决
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