aurelia / framework

The Aurelia 1 framework entry point, bringing together all the required sub-modules of Aurelia.
MIT License
11.75k stars 625 forks source link

Hierarchical (parent/child) select binding #717

Closed sousekd closed 6 years ago

sousekd commented 7 years ago

Hi,

I'd like to submit a bug report

Please tell us about your environment:

Current behavior:

We are having issues when trying to bind two selects (dropdowns) in a typical parent/child scenario, The child dropdown (which is bound to selected parent's children) is not rebound correctly after change of the parent when there is too few items. See this Gist demo to reproduce the issue. You can see there 2 exactly same bindings that differ in number of items only, and one binding with <template> workaround, which solves the issue only partially:

As you can see, the change of selected Parent to both another item or null on the first pair causes the reset of selected Child item. On the second pair, the selected Child item is not reset when another Parent item is selected, but it is reset when null Parent is selected. On the third pair, the selected Child item is reset when another Parent item is selected, but it is not reset when null Parent is selected.

The point is that the first two dropdown pairs are 100% identical, only the amount of data differs. The correctly working (first) one operates on a larger hierarchy, the incorectly working (second) one operates on a smaller set. The third pair of dropdowns is our attempt to workaround the issue by enclosing the child dropdown within <template with="selectedParent"> tag.

Expected/desired behavior:

Thank you very much for looking at this. We love Aurelia and this is one of very few issues we've faced in almost one year of otherwise fantastic experience.

Best Regards, David

sousekd commented 7 years ago

Hi,

We are still struggling with the issue. I believe that having a set of dropdowns for editing hierarchical data on a form has to be quite a common scenario - so maybe we are just doing something completely wrong... Until this is fixed, does anybody know about some elegant workaround?

Thanks again, David

EisenbergEffect commented 7 years ago

@jdanyow Can you provide some insight?

sousekd commented 7 years ago

Ok, the workaround is actually pretty straightforward:

But I still think this should be unnecessary...

jdanyow commented 7 years ago

similar to https://github.com/aurelia/binding/issues/521 has to do with the value the child select is bound to changing prior to the child select's options being updated by the repeat. We may need to put a mutation observer on the select to ensure we can synchronize the selected value after the options change.

Alexander-Taran commented 6 years ago

Indeed it's similar to https://github.com/aurelia/binding/issues/521

one could be closed

EisenbergEffect commented 6 years ago

Closing as duplicate.

bigopon commented 6 years ago

@sousekd fix for this is at https://github.com/aurelia/binding/pull/677