Javascript 将最终表单与物料UI自动完成
我制作了这个组件Javascript 将最终表单与物料UI自动完成,javascript,reactjs,debugging,material-ui,react-final-form,Javascript,Reactjs,Debugging,Material Ui,React Final Form,我制作了这个组件 const AutocompleteAdapter = ({ input, ...rest }) => ( <Autocomplete {...input} {...rest} forcePopupIcon={false} renderInput={params => <TextField {...params} {...input} {...rest} />} /> ); 在react admin上
const AutocompleteAdapter = ({ input, ...rest }) => (
<Autocomplete
{...input}
{...rest}
forcePopupIcon={false}
renderInput={params => <TextField {...params} {...input} {...rest} />}
/>
);
在react admin上创建自定义自动完成组件的过程中,我遇到了相同类型的错误(在木头下面使用react final form) 每次我选择我的选项时,给getOptionLabel函数的值总是0(因此给了我相同的错误) 为了解决这个问题,我添加了一个Autocomplete onChange属性来使用react final form input.onChange prop() 在您的情况下,可能是这样(未经测试):
从“react final form”导入(使用字段)
常量字段=(道具)=>{
常量{name,…restProps}=props
常量{input,meta}=useField(名称)
返回(
(input.onChange(选项)}
...
/>
)
}
<Field
required
name="coach"
label="Coach"
type="text"
placeholder="Enter Coach"
helperText="coach's email"
validate={composeValidators(required, email)}
className={classes.field}
options={mockEmails}
getOptionLabel={option => option}
component={AutocompleteAdapter}
/>
The list is rendered under the autocomplete field but when im typing it dont filter the results, and if i choose one mail of the list i get this error
Material-UI: the `getOptionLabel` method of useAutocomplete do not handle the options correctly.
The component expect a string but received number.
For the input option: 0, `getOptionLabel` returns: 0.
import (useField) from 'react-final-form'
const Field = (props) => {
const {name, ...restProps} = props
const {input, meta} = useField(name)
return (
<Field
...
onChange={(event, option) => (input.onChange(option)}
...
/>
)
}