Check if a validator is disabled
epyx25 opened this issue · comments
I have a model, with a description field, which is some time is required.
model.js
description: validator('presence', {
presence: true,
disabled(model) {
return this.get('model.simple')
}
}),
In my {{form-group}} component the label has a class, if the field is required. (It depends on if the model has a validation on the property)
components/form-group.js
init() {
this._super(...arguments);
var valuePath = this.get('property');
defineProperty(this, 'required', computed.oneWay(`model.validations.attrs.${valuePath}`));
},
hasValidationClass: computed('required', function(){
return this.get('required') ? 'has-error' : '';
}),
components/form-group.hbs
Is there a way to find out if the validator is disabled or not, so I could do something like this?
components/form-group.js
hasValidationClass: computed('required', function(){
return this.get('required') && !this.get('required.disabled') ? 'has-error' : '';
}),