使用redux-form-material-ui的自动完成的redux-form字段

时间:2017-10-20 03:22:09

标签: material-ui redux-form

我正在使用redux-form的自动完成字段,并找到了这个解决方案。认为这将有助于使用material-ui或redux-form-material-ui的人,并希望摆脱muiTheme错误。对于我的情况,我发现使用react-select很简单。

{/* Libraries you need */}

import {AutoComplete as MUIAutoComplete} from 'material-ui'
import { AutoComplete } from 'redux-form-material-ui'
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
import { reduxForm, Field, Fields, formValueSelector, change } from 'redux-form'


{/* redux-form Field component for Text Input using AutoComplete */}

<MuiThemeProvider>
   <Field
    name="searchByText"
    label="Search Suggestions"
    component={AutoComplete}
    floatingLabelText="Search By Suggestions"
    openOnFocus
    filter={MUIAutoComplete.fuzzyFilter}
    dataSource={searchSuggestionList}        //array list of suggestions
    onChange={this.handleSearchByTextChange} //handle the onChange event by handleSearchByTextChange func
    onBlur={() => {}}
  />
</MuiThemeProvider>

0 个答案:

没有答案