backbone.validation
backbone.validation copied to clipboard
Backbone.Validation.bind with labelFormatter option
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!
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.
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.
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.
@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?
+1 for accepting request