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

Implement handling of options that are both disabled AND selected #592

Closed
wants to merge 1 commit into from

Conversation

dingram
Copy link
Contributor

@dingram dingram commented Apr 25, 2012

Allows Chosen to deal with items that are both disabled and selected (i.e. should show as selected but should not be deselectable). See also #516 and #586.

These changes include:

  • Different class/styling on the disabled item
  • Removal of the "x" link on the disabled item
  • Tweaks to backspace-handling, to ignore disabled items
  • An inadvertent fix for the Prototype code (see below)
  • Update to the example files

This change does not update the compiled files, as I appear to have a different version of coffeescript (or different options), and didn't want to create needless changeset noise. This can be updated, however.

Prototype fix

I noticed that in keydown_backstroke (around line 490), it was calling:

@pending_backstroke = @search_container.siblings("li.search-choice").last()

but Prototype does not accept a selector argument to siblings(), so this was doing nothing. In order to replicate the functionality from jQuery, it would have to be something like:

@pending_backstroke = @search_container.siblings().accept( (x) -> x.x.hasClassName("search-choice") ).last()

with an additional tag name check. In any event, I updated the code to use:

@pending_backstroke = @search_container.siblings().reject( (x) -> x.hasClassName("search-choice-disabled") ).last()

as I needed to exclude disabled items, and it appeared to be doing the right thing anyway.

@@ -487,8 +490,8 @@ class Chosen extends AbstractChosen
this.choice_destroy @pending_backstroke.down("a")
this.clear_backstroke()
else
@pending_backstroke = @search_container.siblings("li.search-choice").last()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in the main description, the selector "li.search-choice" has no effect here. In fact, the siblings() method accepts no arguments at all.

@ValterBorges
Copy link

#586 had a bug. here is the fix. sry new to github not sure how to make a formal pull request.

//add if !== undefined

  if(result_data !== undefined)
  {
    result_data.selected = false;
    this.form_field.options[result_data.options_index].selected = false;
  }

@pfiller
Copy link
Contributor

pfiller commented May 26, 2012

Thanks @dingram. I've created a new pull request (#638) that builds on this PR. Would welcome feedback there and hope to merge to master soon.

@pfiller pfiller closed this May 26, 2012
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.

None yet

3 participants