# JS: callback error when called from Each collection

**URL:** <https://forums.fusetools.com/t/js-callback-error-when-called-from-each-collection/1037>\
**Category:** Bug Reports\
**Created:** [October 19, 2015, 9:18pm UTC](https://forums.fusetools.com/t/js-callback-error-when-called-from-each-collection/1037 "2015-10-19T21:18:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![philippe.elsass](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/philippe.elsass/32/416_2.png) [@philippe.elsass](https://forums.fusetools.com/u/philippe.elsass)\
**Post date:** [October 19, 2015, 9:18pm UTC](https://forums.fusetools.com/t/js-callback-error-when-called-from-each-collection/1037/1 "2015-10-19T21:18:45Z")

</div>

I took the TodoApp sample and grouped the actions into a sub-object, as following:

```auto
module.exports = {
    todoList: todoList,
    titleInput: titleInput,
    currentTab: currentTab,
    remainingText: remainingText,
    canClearCompleted: canClearCompleted,
    actions:{
        addItem: addItem,
        deleteItem: deleteItem,
        toggleAll: toggleAll,
        toggleItem: toggleItem,
        clearCompleted: clearCompleted,
        showAll: showAll,
        showActive: showActive,
        showCompleted: showCompleted
    }
};

```

And I then modified `MainView.ux` accordingly:

```auto
<Button Clicked="{actions.addItem}" Width="60" Height="60" HitTestMode="LocalBoundsAndChildren">
...
<Each Items="{todoList}">
    ...
    <Button Clicked="{actions.toggleItem}" Alignment="CenterLeft" Width="60" Height="60">
    ...
    <Button Alignment="CenterRight" Clicked="{action.deleteItem}" Width="60" Height="60"
        HitTestMode="LocalBoundsAndChildren">
    ...
</Each>
...
<Button ux:Name="allButton" Text="" Clicked="{actions.showAll}">

```

The bug: actions within the `<Each>` collection trigger a JS error (“Something went wrong”) while those outside work normally.

---

<div class="post-metadata">

**Author:** ![COCPORN](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/cocporn/32/576_2.png) [@COCPORN](https://forums.fusetools.com/u/COCPORN)\
**Post date:** [October 20, 2015, 7:33am UTC](https://forums.fusetools.com/t/js-callback-error-when-called-from-each-collection/1037/2 "2015-10-20T07:33:54Z")

</div>

Thank you for reporting. 🙂

There is an internal issue raised for this (“Databinding paths does not work on event handlers”).

Currently, a workaround is to expose all handlers in the top level of your module.exports-section.

I can not see from your example code where `Each` comes into play. Do you have some more code to illustrate how this is affected by `Each`?

---

<div class="post-metadata">

**Author:** ![philippe.elsass](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/philippe.elsass/32/416_2.png) [@philippe.elsass](https://forums.fusetools.com/u/philippe.elsass)\
**Post date:** [October 20, 2015, 8:22pm UTC](https://forums.fusetools.com/t/js-callback-error-when-called-from-each-collection/1037/3 "2015-10-20T20:22:14Z")

</div>

I edited the sample code to show the `<Each>` block.

Actions outside it (`actions.addItem`, `actions.showAll`) do work, but the actions inside the collection fail (`actions.toggleItem`, `actions.deleteItem`).

---

<div class="post-metadata">

**Author:** ![COCPORN](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/cocporn/32/576_2.png) [@COCPORN](https://forums.fusetools.com/u/COCPORN)\
**Post date:** [October 21, 2015, 10:01am UTC](https://forums.fusetools.com/t/js-callback-error-when-called-from-each-collection/1037/4 "2015-10-21T10:01:58Z")

</div>

Thank you, I will update our issue. 🙂

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [October 23, 2015, 2:38pm UTC](https://forums.fusetools.com/t/js-callback-error-when-called-from-each-collection/1037/5 "2015-10-23T14:38:22Z")

</div>

Hi Philippe,

This feature is now implemented/issue is resolved, and is expected to roll out in version 0.8.6.

Please let us know if you still have problems with it after that version.

Thanks for your help!
