Skip to content

Refresh after submit #13

Description

@arishojaei

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions