adopted-ember-addons / adopted-ember-addons/ember-cp-validations
Dynamic injection of validation properties – Ember 3.12
- Langage dominant
- JavaScript
- Étoiles
- 439
- Forks
- 172
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
### Environment
- Ember Version: 3.12.0
- Ember CLI Version: 3.12.0
- Ember CP Validations Version: 4.0.0.-beta.9
### Steps to Reproduce
Hi everyone,
I have updated an Ember application from Ember 3.6 - Ember-CP 4.0.0-beta.5 to the versions listed above.
My application had the following validation code on a **PromiseObject**. The `buildLogic()` method was called from a property observer once a specific "logic" property was loaded on object creation.
```js
var Product = DS.PromiseObject.extend({
buildLogic(content) {
let validations = {};
for (let property of Object.keys(this.get('properties'))) {
/* Other code to set up validations... */
validations[`codeParts.${property}`] = validator('codePart', {dependentKeys});
}
this.reopen(buildValidations(validations));
}
})
```
This code was correctly checking every `product.${property}` for validation, and the global `validations.isValid` was correctly set and observable.
I have moved the whole code in a new **Component**, as follows:
```js
export default Component.extend({
didInsertElement() {
this._super(...arguments);
const validations = {};
for (let property of Object.keys(this.properties)) {
/* Other code to set up validations... */
validations[`codeParts.${property}`] = validator('codePart', {dependentKeys});
}
this.reopen(buildValidations(validations));
}
});
```
In this case, if I check validation for the single `product.${property}`, it works correctly, updating the property every time the observed value changes.
The global `validations.isValid`, though, is not accessible at all, neither in the component code (setting an observer on the `validations.isValid`) or by `{{log this.validations.isValid}}`.
Interestingly, if I `{{log this}}` on the component, the console will show an Ember object with `validations` property set, but if I `{{log this.validations}}` or if I `{{log validations}}`, it returns undefined.
Anyone knows what the reason may be?
Thanks in advance.
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.