【问题标题】:React admin AutocompleteInput does not take value on first clickReact admin AutocompleteInput 在第一次点击时没有价值
【发布时间】:2020-02-19 18:48:29
【问题描述】:

我添加了自动完成输入来选择我的作者。当我在 AutocompleteInput 中搜索作者的姓名并单击我要显示的相同名称时,它不会显示所选值。当我第二次这样做时,它会显示之前选择的值。

这是我的代码,

     <AutocompleteInput source="AuthorUid" label="Author" choices={this.state.authorList}))}/>

【问题讨论】:

    标签: reactjs react-admin


    【解决方案1】:

    因此,我通过为其创建自定义自动完成输入来解决此问题。我不知道 React 管理员的 AutocompleteInput 有什么问题。

    我的自定义组件 ->

     renderSelectField = ({ input, label, meta: { touched, error }, children, ...custom }) => {
        const dropdownMenuProps = {
            menuStyle: {
                top: "360px",
                height: "347px",
                left: "79px",
            },
        }
    
        return(
            <MuiThemeProvider>
                <SelectField
                    floatingLabelText={label}
                    errorText={touched && error}
                    {...input}
                    dropDownMenuProps={dropdownMenuProps}
                    onChange={(event, index, value) => input.onChange(value)}
                    children={children}
                    {...custom}/>
            </MuiThemeProvider>
        );
    }
    

    我使用了我的自定义组件,例如 ->

    <Field name="AuthorUid" component={this.renderSelectField} label="Author">
                 { authors.map((author) => 
                    <MenuItem value={author.id} primaryText={author.name} />
                 })}
    </Field>
    

    【讨论】:

      猜你喜欢
      • 2020-05-19
      • 2022-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 2021-08-12
      相关资源
      最近更新 更多