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

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Dec 26, 2014

Owner

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

Owner

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

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Feb 1, 2015

Owner

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 :)

Owner

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

This comment has been minimized.

Show comment
Hide comment
@tamtakoe

tamtakoe 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);

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

This comment has been minimized.

Show comment
Hide comment
@Jokero

Jokero Feb 2, 2015

Contributor

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

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Feb 5, 2015

Owner

Sure, sounds like a resonable feature request.

Owner

ansman commented Feb 5, 2015

Sure, sounds like a resonable feature request.

@ansman ansman closed this in 1b65319 Feb 5, 2015

@ansman

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Feb 5, 2015

Owner

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.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@Jokero

Jokero Feb 6, 2015

Contributor

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

Contributor

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

This comment has been minimized.

Show comment
Hide comment

tamtakoe commented Feb 6, 2015

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