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

New way to define fields, messages and callbacks #184

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

New way to define fields, messages and callbacks #184

wants to merge 6 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Mar 21, 2016

New way to define fields and set their custom messages for each rules.

var validator = new FormValidator("form" , {
    "email1,email2": {
        rules: "required|valid_email",
        messages: {
            required:       "Custom rule message",
            valid_email:    "Custom rule message"
        }
    },
    pass: {
        rules: "required|min_length[6]|max_length[20]"
        messages: {
            required:       "Custom rule message",
            min_length:     "Custom rule message",
            max_length:     "Custom rule message"
        }
    }
}, function(errors, event) {
    if (errors.length > 0) {
        console.log(errors);
    }

}).onSuccess(function() {
    console.log("Success!");

}).onFail(errors, event) {
    console.log("Error :(");

});

The fields are defined by a single object where each key represents the
name of one field or many fields separated per a comma
New argument in the constructor to pass a object with custom messages
for each field and their corresponding rules
@ghost ghost changed the title Master New way to define fields and messages Mar 21, 2016
The messages must to be defined in the "fields" argument
The setRules() method was updated with the new way of define fields
Was added two methods to handle the callbacks when the form is
submitted. The callback in the constructor is an "always" callback but
it is optional
@ghost ghost changed the title New way to define fields and messages New way to define fields, messages and callbacks Mar 22, 2016
@frangeris
Copy link

Exactly what I was looking for, a "short way to define rules", this should be optional of course, what about this @rickharrison?

@ghost
Copy link
Author

ghost commented Jun 16, 2017

Hi @frangeris, you should check my library which was inspired in this one.

@veksen
Copy link

veksen commented Oct 13, 2017

@voyagercodes in ingles por favor ;)

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

Successfully merging this pull request may close these issues.

3 participants