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

Updating items and groupName results in error #509

Open
svdsande opened this issue Jan 19, 2023 · 2 comments
Open

Updating items and groupName results in error #509

svdsande opened this issue Jan 19, 2023 · 2 comments

Comments

@svdsande
Copy link

Describe the bug
Trying to move or drag any item after updating both items and groupName results in an error.
Uncaught TypeError: this.sortableGroup is undefined

To Reproduce

<ol {{sortable-group groupName=this.groupName onChange=this.reorderItems}}>
  {{#each this.items as |item|}}
    <li {{sortable-item groupName=this.groupName model=item}}>
      {{item}}
      <span class='handle' {{sortable-handle}}>&varr;</span>
    </li>
  {{/each}}
</ol>

<p>The last dragged item was: {{this.lastDragged}}</p>

<button {{on "click" this.updateDataSource}} type="button">Change data source</button>
export default class FooComponent extends Component {
    @tracked lastDragged;
    @tracked items = ['A', 'B', 'C'];
    @tracked groupName = 'foo_01';

  @action
  reorderItems(itemModels, draggedModel) {
    this.items = itemModels;
    this.lastDragged = draggedModel;
  }

  @action
  updateDataSource() {
    this.groupName = 'foo_02';
    this.items = ['D', 'E', 'F'];
  }
}
  1. Render component
  2. See default rendered items (A, B, C)
  3. Click "Change data source" button
  4. See items are changed (D, E, F)
  5. Try to move any given item
  6. See error

Expected behavior
Should be able to move items after they are updated.

@Ekluv
Copy link

Ekluv commented Sep 4, 2023

try {{#each this.items key="@index" as |item|}}. it works for me

@mike183
Copy link

mike183 commented Oct 5, 2023

Hey @svdsande, did you ever find a solution/workaround for this?

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

3 participants