Last active
February 4, 2016 19:29
-
-
Save offirgolan/4518559f3903054dcf00 to your computer and use it in GitHub Desktop.
conditional validations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import DS from 'ember-data'; | |
import { buildValidations, validator } from 'ember-cp-validations'; | |
/** | |
* Only enable validations on proName and proTeam if join_as_pro is set to true | |
*/ | |
const Validations = buidlValidations({ | |
name: [ /* name validations */ ], | |
password: [ /* password validations */ ], | |
proName: { | |
dependentKeys: ['join_as_pro'], | |
disabled() { | |
return !this.get('model.join_as_pro'); | |
}, | |
validations: [ /* proName validations */ ] | |
}, | |
proTeam: { | |
dependentKeys: ['join_as_pro'], | |
disabled() { | |
return !this.get('model.join_as_pro'); | |
}, | |
validations: [ /* proTeam validations */ ] | |
} | |
}) | |
export default DS.Model.extend(Validations, { | |
name: DS.attr('string'), | |
password: DS.attr('string'), | |
proName: DS.attr('string'), | |
proTeam: DS.attr('string'), | |
join_as_pro: false | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like the buildValidations function does not expect the object instead of the validation directly, I get this: