-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
clear
should set attributes to defaults
#3395
Conversation
a62f03a
to
2a17d0c
Compare
I think most often when you clear the model you want it cleared. You can always reset the initial state after. |
var attrs = {}; | ||
for (var key in this.attributes) attrs[key] = void 0; | ||
return this.set(attrs, _.extend({}, options, {unset: true})); | ||
var attrs = _.defaults({}, attrs, _.result(this, 'defaults')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is attrs
coming from? typo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh thanks!
Agreed with @akre54 on the semantics of |
2a17d0c
to
c286928
Compare
Are we talking about a |
This functionality can be achieved pretty easily like so:
To avoid a double-flash in your view, you could add a custom option to the |
I think simpler wins out here. Thanks anyways. |
- Adds `{ reset: true }` flag to `#set` that deletes any attributes that are not specified - Adds ‘reset’ event mirroring `Collection`’s. Fixes jashkenas#3253, jashkenas#3395. I could really use help naming the `validateCombined` option. I need to validate only the passed in `attrs` (both `#clear` and `#reset` specify _exactly_ what the attributes will be), not the merged `attrs` `attributes`.
When i defined
defaults
attributes, onclear
those values are not retrieved.