christianalfoni / formsy-react

A form input builder and validator for React JS
MIT License
2.6k stars 438 forks source link

Removing all fields may cause empty form to be invalid #485

Open varzager opened 6 years ago

varzager commented 6 years ago

I have a scenario that i have a form with a few inputs, and 1 input is invalid. Then i remove ALL inputs from the form. and the form stays invalid, even though it is empty => valid. I think this happens is because Formsy runs validation only when it has at least one input.

It seems the function validateForm in main.js validates only forms that contain at least 1 input.

I believe adding isValid: true, would fix that:

if (!this.inputs.length) {
      this.setState({
        canChange: true,
        isValid: true,
      });
    }

What do u think?

Thanks

rkuykendall commented 6 years ago

This is an interesting issue. If you're still interested, can you re-create it in the new formsy organization? https://github.com/formsy/formsy-react