Initial changeset in a componment and changeset stop updatting as attribute updates


#1

I am trying to initialize a changeset in my component init:

import Ember from 'ember';
import DS from 'ember-data';
import Changeset from 'ember-changeset';
import lookupValidator from 'ember-changeset-validations';
export default Ember.Component.extend({
  init(){
    this._super(...arguments);
    let model = this.get('report');
    let validator = this.get('validator');
    this.changeset = new Changeset(model, lookupValidator(validator), validator);
    console.log('changeset defined!');
    console.log(this.changeset);
  },
....

This is for a route that edits the report model, and in the route I have RSVP loaded multiple models including reports, report and others.

The reports model is used to create a list of links to other report models.

When I load this route ( say loading reports/1), I gets the correct changeset, and things works as expected.

However, when I transition to a different report model (reports/2), the changeset does not update, and stays the same (showing reports/1 content) no matter what I do.

I thought it is due to the changeset is created at init(). But even as I change it to didReceiveAttrs(), the same issue persists. I am assuming this is due to I loaded all the attrs in the reports call, so the transition does not require additional Attr thus not triggering didReceiveAttrs()

In a different try, where I create changeset in template with the “with” template helper:

{{#with (changeset section validator) as |changeset|}}
    {{some-form}}
{{/with}}

I managed to get the correct behavior, the changeset updates when I choose different report model. But I am also hoping to do some computed properties that requires changeset object be accessible from within component.

What is the right way create Changeset in this case? Is there a component event that will solve my use case? Or, is there a way to access the aliased “changeset” object created with the “with” helper in template from the component?

Hope this makes sense…


#2

Did you find a solution to this? I am having a similar issue. I have computed properties I want on the component that depend on aspects of the changeset. But when using the with helper I cannot observer or compute based on changeset.