backbone.validations
backbone.validations copied to clipboard
Conditional Validations
Hi, thanks for the plugin - really useful.
I wonder if you knew how to implement conditional logic - the model has two attributes, company and person. On completing the form, validation should fail only if both are left empty.
would you have an idea how to structure this?
thanks
+1
Or you could do:
validate:
keywords:
custom: 'is_location_set'
location:
custom: 'is_keyword_set'
is_location_set: (attr, value) =>
if @get(attr) is '' and @get('location') is ''
'no location'
is_keyword_set: (attr, value) =>
if @get(attr) is '' and @get('keywords') is ''
'no keywords'