gcanti / tcomb-form

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

Provide a method of getting value of invalid form #370

Closed thugcee closed 4 years ago

thugcee commented 7 years ago

Version

Tell us which versions you are using:

Expected behaviour

Since there is Form.validate(), Form.getValue() should return a value without validation or provide a separate method to get a form value without validation.

This is required for all kinds of programmatic form filling based on user's selections in the form. For example, in some order form, one would like to copy customer's address to shipping address.

Actual behaviour

Form.getValue() returns null for invalid forms, thus forcing developer to read all fields values one by one using form.getComponent(path) to recreate form's state.

Or maybe there is already some other way to do this?

Steps to reproduce

  1. create a form with required fields
  2. allow user to fill some fields and click a button
  3. in the button's onClick handler, try to programmatically fill the rest of the fields
bpicolo commented 7 years ago

It's digging into not-really-public interfaces, but:

this.refs.form.refs.input.getValue()

does the trick

gcanti commented 7 years ago

https://github.com/gcanti/tcomb-form/blob/master/GUIDE.md#validate

thugcee commented 4 years ago

https://github.com/gcanti/tcomb-form/blob/master/GUIDE.md#validate

form.validate().value works. Thank you.