I have my Chosen form elements inside a collapsiblock block. If the status of the block is expanded, the chosen elements on the form initialize properly with their minimum width. However, if the collapsiblock containing the form element is collapsed when the page loads initially, then the Chosen elements inside have a zero-width.

After poking around a bit with the chosen.jquery library, I believe the solution is to specify the minimum width as an option like so inside of the module's provided chosen.js script:

options.width = Drupal.settings.chosen.minimum_width+'px';

I'll follow up opening this issue with a patch that proposes to do this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tlarrieu’s picture

Attaching patch file with suggested fix.

mstrelan’s picture

Status: Active » Needs review
FileSize
553 bytes

Attached patch is more respectful of the width as a minimum, as it will only force the width if the computed width is less than the minimum. It requires at least v0.9.13 of Chosen JS. I wonder if we could also tap in to vertical tabs and collapsible fieldsets to use a truly automatic width.

Mołot’s picture

Works for me, but I needed to apply it manually. Now that part looks like that for me:

      $(Drupal.settings.chosen.selector, context)
        .not('#field-ui-field-overview-form select, #field-ui-display-overview-form select') //disable chosen on field ui
        .each(function() {
        if ($(this).find('option').size() >= Drupal.settings.chosen.minimum) {
          options.width = (($(this).width() < minWidth) ? minWidth : $(this).width()) + 'px';
          $(this).chosen(options);
        }
      });
FabianMeul’s picture

#2 is working for me! Thx!

Lex-DRL’s picture

Confirming, patch from #2 works for me, too.

Mołot’s picture

Status: Needs review » Reviewed & tested by the community
Hydra’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

For me this looks like a duplicate of https://drupal.org/node/2051119#comment-7688649 wich is commited now. If this is still an issue, please reopen.