我对使用 React Admin 的项目有以下要求。在编辑屏幕中,我想自定义 selectInput 组件,以便它不是下拉列表,而是弹出窗口中的选项。当我单击输入时,我想要打开一个弹出窗口,并且我想知道如何更改 selectInput 的值,因为知道它来自组件源。 主要问题是我不知道如何手动更改输入的值以使其符合 React Admin 的逻辑。
在表单中设置字段值是这样的 useFormState,setValue:
import { useFormContext } from 'react-hook-form'
function MySelectInput() {
const { setValue } = useFormContext()
const value_from_popup = ...
useEffect(() => {
setValue('my_field', value_from_popup, { shouldValidate: true, shouldDirty: true })
}, [value_from_popup, setValue])
return <SelectInput source="my_field" choices={ ... } />
}