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

%{value} in format message #32

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

%{value} in format message #32

nyrsimon opened this issue Feb 12, 2015 · 5 comments
Milestone

Comments

@nyrsimon
Copy link

@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
Copy link
Owner

@ansman 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
Copy link
Author

@nyrsimon 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
Copy link
Author

@nyrsimon 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
Copy link
Owner

@ansman 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
Copy link
Owner

@ansman 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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