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

Allow form.commit() to trigger only one change event on model #18

Closed
burin opened this issue Oct 31, 2011 · 3 comments
Closed

Allow form.commit() to trigger only one change event on model #18

burin opened this issue Oct 31, 2011 · 3 comments

Comments

@burin
Copy link

burin commented Oct 31, 2011

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.

@mjtamlyn
Copy link
Contributor

mjtamlyn commented Nov 2, 2011

I agree this is expected behaivour. We should keep the Field.commit method, but it shouldn't be used by the Form.commit method.

@philfreo
Copy link
Collaborator

agreed -- it's a pretty major bug that change gets fired for each field one by one.

@powmedia
Copy link
Owner

Fixed in release 0.7

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

4 participants