NewOldMax / react-form-validator-core

Core validator component for react forms
MIT License
94 stars 44 forks source link

isFormValid() issue #41

Closed pavanshinde47 closed 5 years ago

pavanshinde47 commented 5 years ago

Hi @NewOldMax ,

Thanks for providing the isFormValid() method to get the form state if its valid or not.

I was trying to use it in the validatorListener but it keeps going into infinite loop. Where do you suggest we should use isFormValid() method?

NewOldMax commented 5 years ago

Hi, here is an example with isFormValid function. It disables submit button on invalid state case

pavanshinde47 commented 5 years ago

In my form it showing false even if i fill all the required fields.

pavanshinde47 commented 5 years ago

on onError isn't firing :(

NewOldMax commented 5 years ago

But it works in example. Maybe you have some issue in your form logic

pavanshinde47 commented 5 years ago

Yeah, I didn't used validateListener, my bad.

pavanshinde47 commented 5 years ago

this.setState({ isFormValid: this.form.isFormValid() }) this works in some cases and others it throws error Uncaught TypeError: _ValidationRules2.default[name] is not a function

NewOldMax commented 5 years ago

Can you reproduce it here?

pavanshinde47 commented 5 years ago

Hi @NewOldMax Can you check this example

Here I have used PureComponent and handleError = () => { this.setState({ disabled: !this.form.isFormValid(false) }); };

When i type something, the pages becomes unresponsive, can you help me with why this is happening.

mike-strauch commented 5 years ago

I think the problem in your example is that you're using handleError as both the form onError handler and also the validatorListener on the field. If you use isFormValid() instead of isFormValid(false) it seems to work ok.

When you call isFormValid(false) that causes the validatorListener to be called on each field and since validatorListener is calling isFormValid you get into an infinite loop.

I haven't seen that other error you mentioned (Uncaught TypeError: _ValidationRules2.default[name] is not a function) in your example after changing the isFormValid(false) to isFormValid().

NewOldMax commented 5 years ago

Since isFormValid was changed, this issue is not acceptable anymore