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

Comments

Projects
None yet
10 participants
@AndrewRayCode
Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link

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

Andrew Ray
Adding a way to remove chosen from the page, addressing issue harvest…
…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

This comment has been minimized.

Copy link

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

Andrew Ray
updating code to replace tab index properly, and removing chzn-select…
… class style from css, as it doesn't make sense there, issue harvesthq#133
@cevarief

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

AndrewRayCode commented Aug 14, 2011

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

@enhughesiasm

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

balakrishna-gajam commented Nov 23, 2012

Thank you.....cevarief

@DomHudson

This comment has been minimized.

Copy link

DomHudson commented May 1, 2015

Thanks!

@ComeBurguburu

This comment has been minimized.

Copy link
Contributor

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