thefrontside / emberx-form

Form/field components for working with changesets
MIT License
3 stars 1 forks source link

Reset changeset on didUpdateAttrs #16

Closed cherewaty closed 7 years ago

cherewaty commented 8 years ago

Problem

I have a two-column layout where selecting an item from the list in the left column opens an x-form to edit that item in the right column.

If I click an item on the left, I successfully get a form with the right data from that model.

If I click a second (or third, fourth, etc.) item on the left, the x-fields within my x-form don't update to reflect the new model passed in. They stick on the values of the original model selected.

Proposed Solution

Use the x-form component's didUpdateAttrs() hook. The hook will re-initialize the form's attached changeset any time one of the component's attributes (in this case, data), changes.

cowboyd commented 8 years ago

Feels like changeset should be a computed property with data and maybe validations as a dependent key?

cafreeman commented 8 years ago

I'm curious to see how x-form/the initial data are getting created in your use case.

I'm not necessarily opposed to this idea (or @cowboyd's CP idea), but this strikes me as a surprising behavior so I'd like to get a little more context if possible.

cowboyd commented 8 years ago

If I understand from @cherewaty's description, when the value of the data attribute changes, the changeset does not react. It only reacts on component initialization and also on successful submission.

I think that clearly it should do this, but why not have each click correspond to a route transition?

cherewaty commented 7 years ago

Replaced with https://github.com/thefrontside/emberx-form/pull/17