perscrew / react-native-form-validator

React native library to validate form fields
127 stars 55 forks source link

this.isFormValid is always true. #23

Open tejparekh opened 5 years ago

tejparekh commented 5 years ago

When i console.log(this.isFormValid); Result : ƒ isFormValid() { return this.errors.length == 0; }

`import ValidationComponent from 'react-native-form-validator';

export default class extends ValidationComponent { constructor(props) { }

// onPress of the Submit button I am invoking this function to validate all my fields. submitCredentials = () => {

    // TODO : Get the Location details 
    // TODO : Validate the type of data in the Regsiter Form 
    // TODO : 
    console.log("Validating the Form"); 
    this.validate({
        _password   : {required: true},
        _email      : {email: true},   // Sample: I am entering the "sdfjhsbdjfh" in the email field
        _name       : {required: true},
        _lastname   : {required: true},
        _phone      : {numbers: true}, 
        _alias_name : {required: true},
        _isd        : {required: true},
    })
    console.log(this.isFormValid); // returns the function on console
    if(this.isFormValid){   // Always true even if incorrect data is entered in form. 
        this.fireRegisterAPI();
    }

}`

Please help with the solution. What am I missing here? Any setup issue? TIA

asdf23 commented 4 years ago

You are logging the function not calling the function console.log(this.isFormValid()) not console.log(this.isFormValid)