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

Ensure choice count is reflective of actual selected item count. #1171

Merged
merged 11 commits into from
May 23, 2013

Conversation

pfiller
Copy link
Contributor

@pfiller pfiller commented Apr 26, 2013

Original pull request is #1070 by @tjarratt

This addresses some apparent issues where the @choices variable can get out of sync with the actual selected options length. It simply returns the number of selected elements on the underlying select box.

@kenearley @stof What do you think of this? I haven't been able to recreate the situation described by @tjarratt, but I don't really have a problem with this. Maintaining a variable with little performance gain seems unnecessary anyways.

I've done some click testing and it seems performant (especially so in modern browsers). In IE8 with 2k+ options, it's slow, but not noticeably slower than master.

Tim Jarratt and others added 7 commits March 5, 2013 17:03
I ran into some issues where updated multi selects from external
javascript would frequently get out of state because the .choices
variable on the Chosen object was no longer the same as the actual
number of options selected.

Instead of having a global variable on the chosen jquery object
(which is relatively fragile because of external changes to the
select element), just calculate it as needed. It's not called often
and this is a fairly fast lookup for jquery and prototype, so I think
this is a safe change.
Conflicts:
	chosen/chosen.jquery.js
	chosen/chosen.jquery.min.js
	chosen/chosen.proto.js
	chosen/chosen.proto.min.js
	coffee/chosen.jquery.coffee
	coffee/chosen.proto.coffee
Testing in Chrome showed this to be anywhere from a 5 to 12 time
speed improvement. It also lets us have one method in abstract instead
of 2.
@tjarratt
Copy link

Thanks for looking into this, I'll see if it fixes the issue we ran into.

@stof
Copy link
Collaborator

stof commented Apr 27, 2013

Looks good to me if performance does not suffer (I haven't tried both versions to compare them)

@pfiller
Copy link
Contributor Author

pfiller commented May 22, 2013

@stof @kenearley I've added a copule more commits to this diff. The first adds some memorization of the choices count -- improving performance overall while removing the likely trouble spots that lead me to make these changes in the first place.

The second fixes an issue with the max_selected_options testing that is done when building a choice (long story short: the test is happening at the wrong time). It's sort of an unrelated issue, but fit nicely into this changeset, so there you have it.

@stof
Copy link
Collaborator

stof commented May 22, 2013

this looks good to me

@kenearley
Copy link

👍

pfiller added 2 commits May 23, 2013 12:18
Conflicts:
	chosen/chosen.jquery.js
	chosen/chosen.jquery.min.js
	chosen/chosen.proto.js
	chosen/chosen.proto.min.js
	coffee/chosen.jquery.coffee
	coffee/chosen.proto.coffee
	coffee/lib/abstract-chosen.coffee
@tjarratt
Copy link

Awesome! 👍

pfiller added a commit that referenced this pull request May 23, 2013
Ensure choice count is reflective of actual selected item count.
@pfiller pfiller merged commit a469c43 into master May 23, 2013
@pfiller pfiller deleted the tjarratt-master branch May 23, 2013 21:41
pfiller added a commit that referenced this pull request Jun 3, 2013
Contributing Guidelines #1236
Wrap for attribute in quotes #963b051ecb
Ensure choice count is reflective of actual selected item count. #1171
Delete choice refactor #1232
Fix scroll issue in Prototype version #1213
Use the better supported offsetWidth property to get a fields width #1172
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

Successfully merging this pull request may close these issues.

4 participants