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

There is no way to remove chosen from the page #133

Closed
AndrewRayCode opened this issue Aug 2, 2011 · 14 comments
Closed

There is no way to remove chosen from the page #133

AndrewRayCode opened this issue Aug 2, 2011 · 14 comments

Comments

@AndrewRayCode
Copy link

@AndrewRayCode AndrewRayCode commented Aug 2, 2011

There is no way currently to remove chosen from the page. I think there should be. Maybe $input.unchosen() or $Input.removeChosen(). Not all forms are static.

@dangrossman
Copy link

@dangrossman dangrossman commented Aug 3, 2011

I'm also unable to use Chosen for this reason. When I add new s to the page, calling .chosen() again breaks the selects that have already been .chosen() in the past.

@aziz
Copy link
Contributor

@aziz aziz commented Aug 3, 2011

calling .chosen() again should not break your previously chosened(!) selects since chosen adds a chzn-done class to the selects that have been converted and checks at beginning of the process to see whether a select has been chosened before or not.

@dangrossman
Copy link

@dangrossman dangrossman commented Aug 3, 2011

I have a form where the user can add more selects to the form on button click. I clone a div containing a select element each time the button is clicked, then do $('select').chosen(). All but the most recently added select lists then cease to work (clicking them no longer causes the list of options to open up).

AndrewRayCode pushed a commit to AndrewRayCode/chosen-hacks that referenced this issue Aug 4, 2011
…hq#133. This addes a .unchosen() method to jQuery, and a Element.unchosen() to prototype. This is accomplished by storing the reference to the instantiated chosen item on the element, in jQuery using the data API, and on the DOM element for Prototype
AndrewRayCode pushed a commit to AndrewRayCode/chosen-hacks that referenced this issue Aug 4, 2011
@AndrewRayCode
Copy link
Author

@AndrewRayCode AndrewRayCode commented Aug 5, 2011

I made pull request 147 to address this #147

AndrewRayCode pushed a commit to AndrewRayCode/chosen-hacks that referenced this issue Aug 5, 2011
… class style from css, as it doesn't make sense there, issue harvesthq#133
@cevarief
Copy link

@cevarief cevarief commented Aug 11, 2011

I add jquery unchosen method for this, it removes chosen combobox and get the original combobox back.

  unchosen: function() {
        return $(this).each(function() {
            var element = $(this);
            if(element.hasClass('chzn-done')){
                //remove chosen
                element.next('[id*=_chzn]').remove(); //Make sure its id contain _chzn
                //remove chosen class in original combobox and make it visible
                element.removeClass('chzn-done').css('display','block');
            }
        });
    }

$('#country').unchosen(); or $('.chzn-select').unchosen() will get back the original combo.

@AndrewRayCode
Copy link
Author

@AndrewRayCode AndrewRayCode commented Aug 14, 2011

Your code doesn't replace the tab index nor remove the event listener from the input, which is done in my pull request

@cevarief
Copy link

@cevarief cevarief commented Aug 14, 2011

Isn't that methode remove() will also remove bound events and jQuery data associated with the element? My apologize I'm not quite good here, it's just my quick and dirty solution.
Since i don't specify tabindex so pressing tab between element in a form still work fine after unchoosing.

@AndrewRayCode
Copy link
Author

@AndrewRayCode AndrewRayCode commented Aug 14, 2011

There is an event added to the original select box by jQuery / prototype

@enhughesiasm
Copy link

@enhughesiasm enhughesiasm commented Nov 4, 2011

+1 for this.

DelvarWorld's .unchosen() fork works brilliantly but I can't upgrade to the latest version of chosen as I lose the ability to .unchosen() - and sadly there are bugs in the old version that I am having to fix myself rather than upgrade to the fixed new version!

@Capit0L
Copy link

@Capit0L Capit0L commented Jul 11, 2012

This is little plugin to remove chosen.

$.fn.chosenDestroy = function () {
$(this).show().removeClass('chzn-done').removeAttr('id');
$(this).next().remove()

  return $(this);

}

For examle: $('select[name=countries]').chosenDestroy()

@andreaslyngstad
Copy link

@andreaslyngstad andreaslyngstad commented Nov 20, 2012

@Capit0L Thanks!

Don't see the need for .removeAttr('id') in the newest version.

This works

$.fn.chosenDestroy = function () {
$(this).show().removeClass('chzn-done')
$(this).next().remove()

  return $(this);
}
@balakrishna-gajam
Copy link

@balakrishna-gajam balakrishna-gajam commented Nov 23, 2012

Thank you.....cevarief

@DomHudson
Copy link

@DomHudson DomHudson commented May 1, 2015

Thanks!

@ComeBurguburu
Copy link
Contributor

@ComeBurguburu ComeBurguburu commented May 1, 2015

$input.chosen("destroy") #2290

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

10 participants