Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic injection of validation properties – Ember 3.12 #655

Open
danieledraganti opened this issue Aug 26, 2019 · 0 comments
Open

Dynamic injection of validation properties – Ember 3.12 #655

danieledraganti opened this issue Aug 26, 2019 · 0 comments

Comments

@danieledraganti
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant