powmedia / backbone-forms

Form framework for BackboneJS with nested forms, editable lists and validation
MIT License
2.17k stars 415 forks source link

Nested List causes duplicate events on Add button #502

Closed miketonks closed 8 years ago

miketonks commented 8 years ago

I'm using a list of NestedModel which contains a list.

// Model class for each ResourceSelector item var FooSelectorModel = Backbone.Model.extend({ schema: { name: 'Text', tags: { type: 'List', itemType: 'Text' } } });

// Model class for each Rule item var MyModel = Backbone.Model.extend({ defaults: { }, schema: { service: 'Text', foo_selector: { type: 'List', itemType: 'NestedModel', model: FooSelectorModel } } });

All works really well except one thing. When I click 'Add' button on child list, it adds to both child and parent list.

We traced this down to the click event scope: 'click [data-action="add"]'

which although it's limited by DOM scope, the child node is inside the parent node, so event propagates to parent.

I will submit pull request with simple fix: event.stopPropagation();

miketonks commented 8 years ago

https://github.com/powmedia/backbone-forms/pull/503