blueberryapps / onion-form

React Redux form builder with great UX validations
49 stars 2 forks source link

Proper clearing form field values #29

Open tomwagner opened 7 years ago

tomwagner commented 7 years ago

I think that proper way to clean forms values could be set them to undefined value: https://github.com/blueberryapps/onion-form/blob/5c7869b2e42d6fd68e3c5398771995c1a813788d/src/reducer.js#L12

Now it's clearing to empty string, but this value can be also a user input. And in functionality of setting defaultValue to Input doesn't work correctly. There is one condition which set input fields to defaultValue only if they are undefined: https://github.com/blueberryapps/onion-form/blob/5c7869b2e42d6fd68e3c5398771995c1a813788d/src/connectField.js#L132-L135

So for example if i have one form where some input (eg. select) has defaultValue and i clear this form by action clearForm it clears all values in state with empty string, but default value of this select won't be set because of condition above.