Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Materialize inputs not triggering onChange in React?

I have a Materialize input like so:

<input type="date" className="datepicker" onChange={this.props.handleChange} />

It is being correctly initialised by Materialize, but not firing onChange when the value of the datepicker changes. What am I doing wrong here? This problem seems to extend to all Materialize inputs.

like image 471
j_d Avatar asked Jan 27 '16 10:01

j_d


1 Answers

On componentDidUpdate() using a prop id

var elem = document.getElementById('date');
        M.Datepicker.init(elem,{
            onClose:()=>{
                this.state.date = elem.value;                    
                this.setState(this.state)
            }
        });
like image 97
Camilo Barbosa Avatar answered Oct 19 '22 10:10

Camilo Barbosa