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

Trouble extending Validator #68

Closed
NoumanSaleem opened this issue Mar 9, 2012 · 1 comment
Closed

Trouble extending Validator #68

NoumanSaleem opened this issue Mar 9, 2012 · 1 comment

Comments

@NoumanSaleem
Copy link

When running my custom 'validState' validation, the param 'str' comes out as undefined.

https://gist.github.com/2004334

Any idea?

@chriso
Copy link
Collaborator

chriso commented Mar 19, 2012

When the methods are chained together you can access the string with this.str rather than as a parameter

Validator.prototype.validState = function () {
    if (states.indexOf(this.str) === -1) {
        this.error(this.msg || 'Invalid state');
    }
    return this;
}

//then
check('AK').validState();

@chriso chriso closed this as completed Mar 19, 2012
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

2 participants