Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make onValidated callback fire when event is not defaultPrevented #16

Open
ImBobby opened this issue Mar 9, 2017 · 0 comments
Open

Comments

@ImBobby
Copy link
Owner

ImBobby commented Mar 9, 2017

Given markup

<form>
    <div>
        <label>Name</label>
        <input type="text" required>
    </div>
    <div>
        <label>
            <input id="dAgree" type="checkbox">
            <span>I agree with the terms and conditions</span>
        </label>
    </div>
    <button>Submit</button>
</form>

JS

$('form').bazeValidate({
    onValidating: function (e) {
        if ( !$('#dAgree').is(':checked') ) {
            e.preventDefault();
            $('#dAgree').parent().after('<div class="msg-error">You have to agree.</div>')
        }
    },
    onValidated: function (e) {
        e.preventDefault()
        alert('thank you!')
    }
});

The snippet above would reach alert when the input text is filled and checkbox is unchecked. onValidated function should not run if the event is defaultPrevented in onValidating callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant