2017-06-21 58 views
0

我正在嘗試爲redux表單與redux-form-material-ui創建一個自動完成。不過,我堅持onUpdateInput沒有解僱這個問題。這裏是我的代碼部分相關的自動完成onUpdateInput不會在redux表單材質ui上觸發?

import { Field, reduxForm } from 'redux-form'; 
import { DatePicker, AutoComplete } from 'redux-form-material-ui'; 
class autocompleteComponent extends React.Component { 

    onChange = value => { 
     //this is firing properly 
    } 

    onSearch = value => { 
    //this is not firing at all 
    const { getPatients } = this.props; 
    if (value.length) { 
     getPatients(value); 
    } 
    } 

    render() { 
     const { patientData} = this.props; 
     return (
      <Field 
       id="patient-no" 
       name="patientNo" 
       hintText="Patient No" 
       component={AutoComplete} 
       dataSource={patientData} 
       dataSourceConfig={{ text: 'patientNo', value: 'patientNo' }} 
       onNewRequest={value => this.onChange(value)} 
       onUpdateInput={value => this.onSearch(value)} 
       filter={(searchText, key) => true} 
       fullWidth={true} /> 
    ) 
    } 
} 

如果有人可以幫助我,或有這方面的一些提醒,請不要讓我知道。感謝

回答

0

你可以試試這個

import { Field, reduxForm } from 'redux-form'; 
import { DatePicker, AutoComplete } from 'redux-form-material-ui'; 
class autocompleteComponent extends React.Component { 

    onChange(value) { 
    //this is firing properly 
    } 

    onSearch(value) { 
    const { getPatients } = this.props; 
    if(value.length) { 
     getPatients(value); 
    } 
    } 

    render() { 
     const { patientData} = this.props; 
     return (
      <Field 
       id="patient-no" 
       name="patientNo" 
       hintText="Patient No" 
       component={AutoComplete} 
       dataSource={patientData} 
       dataSourceConfig={{ text: 'patientNo', value: 'patientNo' }} 
       onNewRequest={value => this.onChange(value)} 
       onUpdateInput={this.onSearch.bind(this)} //no need to pass any value 
       filter={(searchText, key) => true} 
       fullWidth={true} /> 
    ) 
    } 
}