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

%{value} in format message #32

Closed
nyrsimon opened this Issue Feb 12, 2015 · 5 comments

Comments

Projects
None yet
2 participants
@nyrsimon

nyrsimon commented Feb 12, 2015

Firstly - awesome stuff you are building here, it's a big help!!

Am I doing something wrong - I'm trying to include the value of the field being tested in the custom error message. This works fine on inclusion but not on the 'format' check.

For example, this works great

currency: {
    presence: true,
    length: {is: 3},
    inclusion: {
        within: ccys,
        message: '%{value} is not a valid currency'
    },
    format: {
        pattern: /^[A-Z]{3}$/,
        message: 'is in an invalid format'
    }
}

But if I go with this

transaction_time: {
    presence: true,
    length: {is: 8},
    format: {
        pattern: /^[0-2][0-3]:[0-5][0-9]:[0-5][0-9]$/,
        message: '%{value} is in an invalid format '
    }
}

I get 'Transaction time %{value} is in an invalid format'

Am I doing something wrong or is it just not a feature at this point??

Thanks

@ansman

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Feb 13, 2015

Owner

Not implemented yet, but it's a good idea. I'll make sure to add it to the backlog!

On Thu, Feb 12, 2015 at 10:15 PM, nyrsimon notifications@github.com
wrote:

Firstly - awesome stuff you are building here, it's a big help!!
Am I doing something wrong - I'm trying to include the value of the field being tested in the custom error message. This works fine on inclusion but not on the 'format' check.
For example, this works great
currency: {
presence: true,
length: {is: 3},
inclusion: {
within: ccys,
message: '%{value} is not a valid currency'
},
format: {
pattern: /^[A-Z]{3}$/,
message: 'is in an invalid format'
}
}
But if I go with this
transaction_time: {
presence: true,
length: {is: 8},
format: {
pattern: /^[0-2][0-3]:[0-5][0-9]:[0-5][0-9]$/,
message: '%{value} is in an invalid format '
}
}
I get 'Transaction time %{value} is in an invalid format'
Am I doing something wrong or is it just not a feature at this point??

Thanks

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

Owner

ansman commented Feb 13, 2015

Not implemented yet, but it's a good idea. I'll make sure to add it to the backlog!

On Thu, Feb 12, 2015 at 10:15 PM, nyrsimon notifications@github.com
wrote:

Firstly - awesome stuff you are building here, it's a big help!!
Am I doing something wrong - I'm trying to include the value of the field being tested in the custom error message. This works fine on inclusion but not on the 'format' check.
For example, this works great
currency: {
presence: true,
length: {is: 3},
inclusion: {
within: ccys,
message: '%{value} is not a valid currency'
},
format: {
pattern: /^[A-Z]{3}$/,
message: 'is in an invalid format'
}
}
But if I go with this
transaction_time: {
presence: true,
length: {is: 8},
format: {
pattern: /^[0-2][0-3]:[0-5][0-9]:[0-5][0-9]$/,
message: '%{value} is in an invalid format '
}
}
I get 'Transaction time %{value} is in an invalid format'
Am I doing something wrong or is it just not a feature at this point??

Thanks

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

@nyrsimon

This comment has been minimized.

Show comment
Hide comment
@nyrsimon

nyrsimon Feb 13, 2015

OK thanks - I'll try to take a look and see if I can cook up the change. Would love to add something back

nyrsimon commented Feb 13, 2015

OK thanks - I'll try to take a look and see if I can cook up the change. Would love to add something back

@nyrsimon

This comment has been minimized.

Show comment
Hide comment
@nyrsimon

nyrsimon Feb 13, 2015

So took a look. I ended up changing line 740 from

return message;

to

return v.format(message, {value: value});

Would you like me to do a pull request?

nyrsimon commented Feb 13, 2015

So took a look. I ended up changing line 740 from

return message;

to

return v.format(message, {value: value});

Would you like me to do a pull request?

@ansman

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Feb 18, 2015

Owner

Well, perhaps we should start supporting adding values to all messages in which case this should be done on a higher level. I'll think about the implementation.

Owner

ansman commented Feb 18, 2015

Well, perhaps we should start supporting adding values to all messages in which case this should be done on a higher level. I'll think about the implementation.

@ansman ansman modified the milestones: Next, 1.0 Apr 3, 2015

@ansman ansman closed this in e5d64a4 Apr 8, 2015

@ansman

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Apr 8, 2015

Owner

Released in 0.7.0, all validators now support replacing %{format}

Owner

ansman commented Apr 8, 2015

Released in 0.7.0, all validators now support replacing %{format}

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