-
Notifications
You must be signed in to change notification settings - Fork 302
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
format(), formatLabel() not being added to custom validator #98
Comments
That's very strange... Can you post some code showing how you use them in a model? |
My validation for the ip_address looks like this validation:
ip_address: (value, attr, computedState)->
if @is_master()
if !value
return "Need it"
Backbone.Validation.validators.isIpAddress(value, attr, null, this) BTW - I really have found this validation framework useful. So thanks for that. One of the things I found myself wishing for is conditional validation like Rails has. Without it, I had to implement the validation example above to make sure I only validate the format when some other condition is true. In this case whether it's a master. |
I think the issue lies in the last line, where you call the validators directly. It gets a different context without the format functions mixed in. I'll see if I can get this fixed in the next release. You can have conditional validation (sort of) by specifying the required validator as a function.
Note that if it's not required (e.g isMaster returns false) ip_adress has to be empty or an valid one. Otherwise, it will fail. Hope this helps! |
Thanks Thomas, that's what I was looking for. I didn't realize it was possible since most of the example of using a function are for whole validator rather than a specific rule of a validator. Although I see now that there is a subtle example of this in the docs. |
Will be more explicit about it in the docs. Thanks! |
I have 2 custom validators and for some strange reason, one gets the this.format() and this.formatLabel() methods and the other doesn't.
isDate always gets them, isIpAddress never gets them. I've tried reordering them, renaming them, removing isDate, but no matter what I do isIpAddress never gets them. Any ideas?
The text was updated successfully, but these errors were encountered: