Skip to content
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

Conditional Validations #20

Open
kanejoe opened this issue Feb 28, 2012 · 2 comments
Open

Conditional Validations #20

kanejoe opened this issue Feb 28, 2012 · 2 comments

Comments

@kanejoe
Copy link

kanejoe commented Feb 28, 2012

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

@stoplion
Copy link

stoplion commented Apr 9, 2013

+1

@stoplion
Copy link

stoplion commented Apr 9, 2013

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'

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

No branches or pull requests

2 participants