Remchi/bookworm-react

Refresh after submit

Opened this issue · 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