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

Default values #16

Closed
tamtakoe opened this issue Dec 26, 2014 · 8 comments
Closed

Default values #16

tamtakoe opened this issue Dec 26, 2014 · 8 comments

Comments

@tamtakoe
Copy link

@tamtakoe tamtakoe commented Dec 26, 2014

Often I need to set custom message (or other fields) for all validators. Now I have to write every time:

myField1: {
    email: {
        message: 'invalidEmail'
    }
}
...

myField2: {
    email: {
        message: 'invalidEmail'
    }
}
...

It is better:

validators.defaults.email.message = 'invalidEmail';
...

myField1: {
    email: true
}
...

myField2: {
    email: true
}
@ansman
Copy link
Owner

@ansman ansman commented Dec 26, 2014

Great idea! I'll make sure to implement this when I'm back from my vacation

On Fri, Dec 26, 2014 at 6:08 PM, tamtakoe notifications@github.com
wrote:

Often I need to set custom message (or other fields) for all validators. Now I have to write every time:

myField1: {
    email: {
        message: 'invalidEmail'
    }
}
...
myField2: {
    email: {
        message: 'invalidEmail'
    }
}
...

It is better:

validators.defaults.email.message = 'invalidEmail';
...
myField1: {
    email: true
}
...
myField2: {
    email: true
}

Reply to this email directly or view it on GitHub:
#16

@ansman
Copy link
Owner

@ansman ansman commented Feb 1, 2015

Pushed an implementation of this in d06bd13

Please have a look and see what you think, you can just close the issue if you're satisfied :)

@tamtakoe
Copy link
Author

@tamtakoe tamtakoe commented Feb 2, 2015

Good! But it only for error params, not for options (f.e. dateOnly). There is best practice if you make object with default options (f.e. defaults) and merge it with options.

Using lodash defaults:

var defaults = {
    presence: ...
    ...
}
validators.defaults = defaults; //user can change it

...
//presence validator
_.defaults(options, defaults.presence);
@Jokero
Copy link
Contributor

@Jokero Jokero commented Feb 2, 2015

I think it should be possible to set default value of any validator option. So I agree with @tamtakoe 👍

@ansman
Copy link
Owner

@ansman ansman commented Feb 5, 2015

Sure, sounds like a resonable feature request.

@ansman ansman closed this in 1b65319 Feb 5, 2015
@ansman
Copy link
Owner

@ansman ansman commented Feb 5, 2015

Done, now you should be able to specify both default messages and default options. Please try it out and let me know what you think.

@Jokero
Copy link
Contributor

@Jokero Jokero commented Feb 6, 2015

Thanks! 👍 I tried to use default messages and it's working.
Added comment 1b65319#commitcomment-9617489.
See please #10 (comment) (it's about promises)

@tamtakoe
Copy link
Author

@tamtakoe tamtakoe commented Feb 6, 2015

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.