adopted-ember-addons / adopted-ember-addons/ember-cp-validations
Check if a validator is disabled
- Langage dominant
- JavaScript
- Étoiles
- 439
- Forks
- 172
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
I have a model, with a description field, which is some time is required.
**model.js**
``` javascript
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**
```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**
```HBS
{{#if label}}
{{label}}
{{/if}}
```
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**
```JS
hasValidationClass: computed('required', function(){
return this.get('required') && !this.get('required.disabled') ? 'has-error' : '';
}),
```
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Start by tracing the validation metadata used by model.js and components/form-group.js, especially model.validations.attrs and the validator('presence', ...) configuration. Check how disabled(model) is evaluated and exposed, then verify that the form-group can distinguish an active required validator from a disabled one without changing unrelated validation behavior.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript
- Domaine
- frontend
- Type d'issue
- Fonctionnalité
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100