bookworm-react icon indicating copy to clipboard operation
bookworm-react copied to clipboard

Refresh after submit

Open arishojaei opened this issue 7 years ago • 0 comments

I don't know why but my page refreshed after I clicked on login button even when my fields are not validate. I set e.preventDefault() to onSubmit function and put errors on console.log, when my fields are not validate console.log print right error messages but when every field are valid console.log print undefined.

    onSubmit = (e) => {
        const errors = this.validate(this.state.data);
        this.setState({ errors });

        e.preventDefault();
        console.log('Err: ' + errors.email + ", " + errors.password)
    };

    validate = (data) => {
        const errors = {};

        if(!Validator.isEmail(data.email)) {
            errors.email = "invalid email";
        }
        
        if (!data.password) {
            errors.password = "Can't be blank";
        }
        
        return errors;
    };

q

arishojaei avatar Jun 26 '18 10:06 arishojaei