adopted-ember-addons / ember-cp-validations

Ember computed property based validations

Home Page:https://adopted-ember-addons.github.io/ember-cp-validations/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dynamic injection of validation properties – Ember 3.12

danieledraganti opened this issue · comments

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.

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:

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.