powmedia/backbone-forms — Issue #18: Allow form.commit() to trigger only one change event on model
Author: burin
Created: 2011-10-31 17:01:59+00:00
State: open

When calling `commit()` on a form with more than one updated field, `change` is triggered on the associated model for each changed attribute.

Backbone allows you to `set()` many attributes at once on a `model`. I think this triggers one `change` event, even when more than one attribute is updated. This allows you to listen to the `change` event on a model and fire a function.

Should we build a hash of attributes to change and set them all at once in the `commit()` vs once per field?

My current use case is having a `SearchForm` with an associated `SearchRequestModel`. A `ResultsCollection` references an instance of the `SearchRequestModel` and has a function bound to the `change` event that calls a `fetch`, using the `SearchRequestModel`'s attributes as the parameters to send in the `fetch`.

Basically, when "submitting" the form, I call `commit()` on the `form`, triggering the `change` on the request `model`, which triggers the `collection`'s `fetch`.