-
Notifications
You must be signed in to change notification settings - Fork 176
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
Conversation
Yes it does, I'll update it tomorrow |
Awesome. |
@@ -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; |
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 :)
Awesome. If you could add some tests for this I'll merge it in the next couple days. |
Removed event listeners after unstuck is called. Changed it so that the options are re-rendered on add, remove, reset and sort. This meant that I had to add in extra lines to manage the event listeners to ensure that we don't create a huge number of events.
I feel like this simple change has gotten a lot bigger than I initially anticipated. Let me know what you guys think of the code though and if it needs more detailed comments. I'll try and get some tests written for this ASAP. |
Simple changes rarely are ;) |
Any update on when this is going to be merged? |
Sorry this slipped through the cracks. Given the size of the change I'm tempted to boot on this to your own CollectionView in your app. I know for my app currently we've got all kinds of special behavior for updating models and filtering (see this gist), and I'm tempted to think that this simple change maybe isn't so simple (what happens if you need to do something more advanced, like filtering?). That said, if there are no objections from anyone else I'll merge tomorrow (ping me if I forget). |
Wouldn't more advanced functionality that does filtering be included in a custom handler based on the specific needs of the app? Automatically updating a select based on a changing backbone collection seems to be a fairly common use-case. Thanks! |
Do you have a jsfiddle example somewhere that I can mess with? |
Yeah, this is the updated fiddle that started all of this http://jsfiddle.net/v4rNk/2/ I ran into a problem with this when I was building a registration form that updated the State/County select when the country changed so the select had to be re-rendered on change to the state collection which was triggered after the country changed. I ended up having to manage the select rendering outside of stickit bindings. |
Try loading your stickit copy from rawgit.com. Github is blocking On Sun, Jun 15, 2014 at 2:28 PM, Yousef Cisco notifications@github.com
|
Yeah I just updated my last comment, this link should be working now http://jsfiddle.net/v4rNk/2/ |
I'm going to merge this in, but with a caveat that we should probably rethink this somewhere down the line. This is a fine solution for the general case, but I'm not a big fan of blowing away all the select options each time we add or remove a model. It's fine here, and it helps keep the code smaller, but we'll likely revisit this at some point. Thanks for all your work on this, I'll try to get the next release out soon. |
Updating select from collection automatically
I'm sorry for responding after the merge, haven't been following the repo lately. |
They're not mutually exclusive. This one listens on collection events while I'm still tempted to move this to a recipe given the complexity of the use What are the major benefits of 231 over this one in your eyes?
|
Is it possible to opt-in or opt-out of the added behaviour in this version? or is the refreshing for all collections? this version seems to be doing some magic with events:
removing a listener by triggering the event, doesn't seem right to me... I guess this one has the benefit of also being able to respond to other changes after load... but for me personally i don't see where i'd use that. |
We could probably add logic for opt-in or opt-out but this select re-render was already happening every time the model value was changed, this change simply made it consistent (ie. on colelction update). I know what you mean about the magic with listeners, initially I didn't want to do this but I found that it was the only way to remove previously bound events and set new ones to stop the number of bound events from rapidly growing. Before an event is bound we trigger an event to unbind the previous event, set the new event and define a listener to unbind the new event. I couldn't find an alternative method to do without affecting any other events that the user might have bound to the collection. Could you provide a code example of how this would work with #231 ? |
@akre54 is right about the two not being mutually exclusive.
So the promise makes sure the select is filled with the data whenever it is available. |
The issue remains is that there's no non-hacky way for the user to update the select when they want, calling I ran into problems with this when I was building an address form, the State/County select needed to auto-update whenever the user changed the country so it would show states/counties for that country. Calling |
I understand |
I agree that adding and removing models is probably a special case enough for In our app our dropdowns are checkable and any selected items are hidden
|
maybe it's better to have an |
@pradius-fut 👍 |
This is a solution to issue #188 where select options need to be updated after the collection is changed/updated.