How can you have a harvesthq Chosen dropdown with a dynamic width style?
By default it has a fixed width and if you try to modify it with CSS you will have several p
I had a responsive form, which had lot of CSS rules with media queries, !important, etc and was using chosen with class inheritance option. On resizing, there were often conflicts between chosen and parent css and things would break. I came up with a simple solution that worked for me: recreate chosen dom on every window resize:
jQuery(document).ready(function() {
doResize();
jQuery(window).on('resize', doResize);
});
function doResize() {
// Parent website's code, that would also reorganize select elements on the page
jQuery("select.my-select").removeAttr("style"); // Remove display:none style added by chosen
jQuery("select.my-select").removeClass("chzn-done"); // Remove chzn-done class added by chosen
jQuery(".chzn-container").remove();
jQuery("select.my-select").chosen({
width: '100%',
disable_search_threshold: 10,
inherit_select_classes : true
});
}