Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

%{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

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

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

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 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 as completed in e5d64a4 Apr 8, 2015
@ansman
Copy link
Owner

ansman commented Apr 8, 2015

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants