-
Notifications
You must be signed in to change notification settings - Fork 177
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
Updating select from collection automatically #237
Changes from 2 commits
70d61de
5999133
8d84286
84a8964
4b596e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -556,12 +556,12 @@ | |
// Determine if this option is selected. | ||
var isSelected = function() { | ||
if (!isMultiple && optionVal != null && fieldVal != null && optionVal === fieldVal) { | ||
return true | ||
return true; | ||
} else if (_.isObject(fieldVal) && _.isEqual(optionVal, fieldVal)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
}; | ||
|
||
if (isSelected()) { | ||
option.prop('selected', true); | ||
|
@@ -593,7 +593,14 @@ | |
} | ||
|
||
// Support Backbone.Collection and deserialize. | ||
if (optList instanceof Backbone.Collection) optList = optList.toJSON(); | ||
if (optList instanceof Backbone.Collection) { | ||
// Listen to the collection for all events and trigger an update of the select options. | ||
optList.once('all', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why only once? And why What about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once because the listener is assigned during creation and when it gets triggered it causes it to be recreated I think. The key events would be add, remove, change and sync i think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once because if we used on then we would get a huge number of listeners set against the collection very quickly since the old listener is not deleted after this function is called again and we don't want to manually manage listeners on the collection since that's up to the dev. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I'd rather we do .once('add remove reset') or similar. Triggering on On Fri, May 16, 2014 at 5:13 PM, Yousef Cisco [email protected]:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I thought it might be overkill but thought it would be worth a refresh on every instance instead of limiting to a few and later on having to expand it to cater to a few edge cases. I can update it tomorrow either way :) |
||
var currentVal = getAttr(model, options.observe, options); | ||
applyViewFn.call(this, options.update, $el, currentVal, model, options); | ||
}, this); | ||
optList = optList.toJSON(); | ||
} | ||
|
||
if (selectConfig.defaultOption) { | ||
addSelectOptions(["__default__"], $el); | ||
|
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.
nice. thanks :)