NewOldMax / react-form-validator-core

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

Validity of the whole form #13

Closed pavanshinde47 closed 6 years ago

pavanshinde47 commented 6 years ago

Hi,

Can you add a property or method to the ValidatorForm to see if the whole form is valid or not.

Something like

isValid=()=> { this.childs.map(child => { if(child.isValid) { return true } }); return false }

NewOldMax commented 6 years ago

Hi, for now you can do something like this

<ValidatorForm ref={r => (this.form = r)} >

runFormvalidation = () => {
    const result = this.form.walk(this.form.childs); // result will be true or false
}
vineet-agrawal96 commented 6 years ago

Hi

I called runFormvalidation function from render method then showing continuously warning.

runFormvalidation = () => { if(!isEmpty(this.refs)){ const result = this.refs.form.walk(this.refs.form.childs); // result will be true or false return result } }

warning.js:33 Warning: setState(...): Cannot update during an existing state transition (such as within render or another component's constructor)

NewOldMax commented 6 years ago

As you can see in your warning message, you shouldn't call this function in render method. You should do it in some event action, like onChange

<ValidatorForm onChange={this.runFormvalidation} />
NewOldMax commented 6 years ago

From version 0.4.3 you can use isFormValid method

pavanshinde47 commented 6 years ago

@NewOldMax Thanks

arosas-atix commented 6 years ago

@NewOldMax Hi, I'm currently using the library at the latest version (0.4.4), and I couldn't find a way to use that method, since it's not exposed in the react class. Could you please post an example of how to use it? I tried using it the same way as addValidationRule

NewOldMax commented 6 years ago

@arosas-atix

<ValidatorForm
    ref={r => (this.form = r)}
>

...

this.form.isFormValid();