validation depending on status of other field
Environment
- Ember Version: 2.8.1
- Ember CP Validations Version: 3.0.1
Steps to Reproduce
I'm trying to validate a dropdown value only if a checkbox is selected. How would I do this:
Model: export default DS.Model.extend(Validations, { age_restriction: DS.attr('number', {defaultValue: 0}), isAgeRestricted: Ember.computed.gt('age_restriction', 0), });
isAgeRestricted will return a boolean value. I need to validate the age_restriction is greater than zero only if isAgeRestricted is true.
In your validations you can use the disabled option.
disabled: computed.not('model.isAgeRestricted')
This is what I tried:
const Validations = build({
age_restriction: validator('number', {
disabled: Ember.computed.not('model.isAgeRestricted'),
gt: 0
})
});
Now it's invalid when I select the checkbox and the value is higher than zero
@kchirayus can we close the issue?