gcanti / tcomb-form

Forms library for react
https://gcanti.github.io/tcomb-form
MIT License
1.16k stars 136 forks source link

unable to set state on change #189

Closed shangsunset closed 9 years ago

shangsunset commented 9 years ago

Hi,

i tried to set state on form change, but it didnt work as expected. i couldnt type in the input box when i had a onChange() function. where am i dong wrong? thanks!


  getInitialState: function() {
    return: {
         userInput: {}
    }
  },

  onChange: function(value) {

    this.setState({userInput: value}, function() {
      console.log(this.state.userInput)
    })
 },

   render () {
     return: {
          <div className="col-md-8">
            <Form
              ref="form"
              type={Page}
              options={options}
              onChange={this.onChange} 
              />
            <button className="btn btn-primary" onClick={this.save}>Save</button>
          </div>
        )
      }
gcanti commented 9 years ago
<Form
  ref="form"
  type={Page}
  options={options}
  value={this.state.userInput} // <= this is missing
  onChange={this.onChange} 
/>
shangsunset commented 9 years ago

Thanks a lot!