backbone.validation icon indicating copy to clipboard operation
backbone.validation copied to clipboard

Backbone.Validation.bind with labelFormatter option

Open logicalicy opened this issue 9 years ago • 5 comments

Hello!

This is a question regarding Backbone.Validation.bind and passing the labelFormatter option to it.

Suppose I specify this formatting option in Backbone.Validation.bind: Backbone.Validation.bind(this, { labelFormatter: 'label' }); Despite label being specified, formatting of labels still remains sentenceCase because it looks like Backbone.Validation.bind does not override the default label formatter. sentenceCase appears to be the only label formatting option if Backbone.Validation.bind is used. In end effect, the only way to override the sentenceCase label formatting is by using Backbone.Validation.configure.

Are there any plans to allow overriding of the default label formatter (sentenceCase) when using Backbone.Validation.bind?

Thank you!

logicalicy avatar Mar 23 '15 20:03 logicalicy

Taking a quick look at the source, it does seem like the options should get into the mixin call, but it's not immediately obvious. It wouldn't surprise me if the option gets dropped somewhere.

By any chance, do you have a unit test that could show the error? That would make it much easier to fix.

platinumazure avatar Mar 24 '15 00:03 platinumazure

Apologies for the delayed response - thanks for getting back so quickly! I'm wondering if this JSFiddle is sufficient to demonstrate Backbone.Validation.bind(this, { labelFormatter: 'label' }); not actually formatting with the model's labels.

In the JSFiddle, when you type in an invalid email, the custom labels defined on the model (labels: { EMAIL: 'Email' }) is not used. Instead, the default formatter sentenceCase kicks in and the view renders an error message with "e m a i l" instead of "Email". (I hope I'm making sense here.)

Please let me know if you'd like me to clarify any of the above.

logicalicy avatar Mar 25 '15 16:03 logicalicy

Thanks @logicalicy, that helps a lot. I have a failing unit test on my local branch and will see if I can come up with a fix in the next day or two.

platinumazure avatar Mar 27 '15 00:03 platinumazure

@logicalicy I just created pull request #283 to attempt to fix this; I think it's pretty good but I had to replace a questionable design decision with an equally questionable design decision. Feel free to pull the src/backbone-validation.js script and see if that might work for you?

platinumazure avatar Mar 27 '15 05:03 platinumazure

+1 for accepting request

ButuzGOL avatar Apr 17 '15 16:04 ButuzGOL