A new release of the Drupal Chosen (7.x-2.0-alpha3) module is out, it is now using the new Chosen v1.0 jquery plugin which breaks the SHS Chosen functionality. Patch coming...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jibize’s picture

Status: Active » Needs review
FileSize
4.3 KB

Maybe this would do it?

Redart’s picture

It doesn't work

alumni’s picture

Doesn't work too

tamonten1’s picture

Doesn't work too

OriginalSauce’s picture

Is there a working patch for this?
If chosen is your chosen selector, this module no longer works correctly.

thanks.

idebr’s picture

Issue summary: View changes
FileSize
4.99 KB

Reroll of the patch in #1 plus some code standard fixes.

For the previous commenters: the patch has to be applied to the 7.x-1.x-dev release, since there have been quite a few changes since the latest recommended release.

mibfire’s picture

Does this work? Cos it hasnt worked for me. I tryed on a profile2 form.

JadH’s picture

I applied #6 on dev version and I can confirm it is working properly with chosen.

stBorchert’s picture

  1. +++ b/js/shs.js
    @@ -78,7 +78,7 @@
    +  };
    

    The semicolon is not needed here (see ajax.js for an example). If there are multiple functions in a behavior, there needs to be a comma.
    Since its the only function the closing bracket is not followed by a semicolon or a comma.

  2. +++ b/js/shs.js
    @@ -274,7 +274,7 @@
    +        $('#' + elem_id.replace(/-/g, '_') + '_chosen').remove();
    

    This would break existing functionality of sites using the old plugin.
    Both selectors need to be supported.

  3. +++ b/js/shs.js
    @@ -288,7 +288,7 @@
    +        $('#' + elem_id.replace(/-/g, '_') + '_chosen').remove();
    

    Same as above.

  4. +++ b/js/shs.js
    @@ -485,27 +485,47 @@
    +      settings.chosen = settings.chosen || Drupal.settings.chosen;
    +      var minWidth = settings.chosen.minimum_width;
    +      var minOptionsSingle = settings.chosen.minimum_single;
    +      var minOptionsMultiple = settings.chosen.minimum_multiple;
    +      var minOptions;
    +      // Define options.
    +      var multiple = Drupal.settings.chosen.multiple;
    +      var maxSelectedOptions = Drupal.settings.chosen.max_selected_options;
    

    Is there any reason to extract all these settings into variables?

  5. +++ b/js/shs.js
    @@ -485,27 +485,47 @@
    +      options.disable_search = Drupal.settings.chosen.disable_search;
    +      options.disable_search_threshold = settings.chosen.disable_search_threshold;
    +      options.search_contains = settings.chosen.search_contains;
    +      options.placeholder_text_multiple = settings.chosen.placeholder_text_multiple;
    +      options.placeholder_text_single = settings.chosen.placeholder_text_single;
    +      options.no_results_text = settings.chosen.no_results_text;
    +      options.inherit_select_classes = true;
    

    settings.chosen can be used directly instead of using "options".

  6. +++ b/js/shs.js
    @@ -485,27 +485,47 @@
    +      if (multiple[name] != false) {
    +        minOptions = minOptionsMultiple;
    +      }
    +
    +      if (maxSelectedOptions[name] != false) {
    +        options.max_selected_options = maxSelectedOptions[name];
    +      }
    

    Could you add some comments about the purpose of this and why SHS needs to do this?

stBorchert’s picture

Status: Needs review » Needs work
MPeli’s picture

Hello,

I created a block using Views Global Filter. The block contains a view with an exposed filter (Simple hierarchical select).

I also use Chosen 7.x-2.0-alpha4 and it seems that SHS and Chosen are not working together any more. Chosen is never applied on selects provided by SHS.

Is anyone facing the same problem?

Thank you, Martin.

revagomes’s picture

Status: Needs work » Needs review
FileSize
6.47 KB
9.28 KB

The #6 patch didn't work to me using the latest version of chosen library (v1.1.0).

Here goes a screenshot after apllying the #6 and also a patch that fix this issue.

I've made some improvements and also added the @stBorchert's suggestions.

kungz13’s picture

It doesn't work

j4’s picture

Tried bith 6 and 12, both dont work for me..

Jaya

scottrigby’s picture

Status: Needs review » Reviewed & tested by the community

#12 works perfectly with chosen 7.x-2.0-alpha4+7-dev and shs 7.x-1.6+34-dev, using the Chosen module recommended plugin version. The drush command 'chosenplugin' downloads Chosen library 1.0.0 (https://github.com/harvesthq/chosen/releases/download/1.0.0/chosen_v1.0....).

hauruck’s picture

#12 does work a bit but it does not support the "add new item" option.

Would be great if someone could fix a better patch :-)

joelpittet’s picture

Bump, this works great nice work. The add new item works with what #15.

Yet I'm using chosen: 7.x-2.0-beta4 and shs 7.x-1.6+34-dev

joelpittet’s picture

Status: Reviewed & tested by the community » Needs work
FileSize
153.55 KB

Actually yeah, new items seem to still have an issue with this. Changing this back to needs work. as per #16.

And even some of the existing items don't work.

Lukas von Blarer’s picture

I was unable to get the patch working. Has anyone solved this?

joelpittet’s picture

@Lukas von Blarer I saddly just took the shs elements out of field groups for now. I've added
select:not(.shs-select):visible to the chosen apply selector
on admin/config/user-interface/chosen

ckaotik’s picture

Got it working on my part with some changes, don't have a .patch for it though :/

- using shs-7.x-1.6+54-dev
- using chosen-7.x-2.0-beta4
- using chosen.js v1.1.0

I've disabled Chosen on my specific element, via either @joelpittet's #20 or configuring my views filter to "never" use Chosen. Then I only needed these changes to shs/js/shs.js:

1. Completely replaced the `elementConvertToChosen` function. This will properly initialize Chosen on the newly created <select> object.

/**
 * Convert a dropdown to a "Chosen" element.
 *
 * @see http://drupal.org/project/chosen
 */
elementConvertToChosen = function($element, settings) {
  if (Drupal.settings.chosen) {
    $($element).chosen({width: 'auto'}); // otherwise width is 0px 
    return true;
  }
  return false;
}

2. Replaced `_chzn' with '_chosen' in `updateElements`(line 299 & line 318). This will allow for clean removing of previously created Chosen elements.

guillaumev’s picture

Rerolling #12 for new dev version of shs

guillaumev’s picture

Sorry forgot to attach...

joelpittet’s picture

Status: Needs work » Needs review
pookmish’s picture

Using a SHS in exposed filter on view, #23 helped clean it up, but no options are created in the chosen dropdown.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

@guillaumev awesome, that works with and without a fieldgroup! Thank you

joelpittet’s picture

@pookmish that may be another issue?

joelpittet’s picture

FYI using Chosen v1.3.0 and chosen module 7.x-2.0-beta4 and shs 7.x-1.6+56-dev

Drupa1ish’s picture

#23 works for me too. Thx @guillaumev

Chosen library v1.4.2 + chosen module 7.x-2.0-beta4 + shs 7.x-1.6+58-dev

Drupa1ish’s picture

#23 works, but trying to create items at deeper level, always ends creating the taxonomy item at first level in back-end.
Anyone else has experienced this before?

asghar’s picture

You can use https://www.drupal.org/project/term_hierarchy module and chosen module.

joelpittet’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

With the latest changes this no longer applies. I wonder if the changes can be simplified to avoid the large hunk change?

joelpittet’s picture

This patch did seem to fix SHS inside a hidden vertical tab and loading from there it seems. I tried merging but didn't get too far due to the changes in the JS file

markhalliwell’s picture

Category: Support request » Bug report
Priority: Normal » Major
Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
5.77 KB

Re-roll + a little cleanup with variable declarations/names.

stBorchert’s picture

Category: Bug report » Task
Priority: Major » Normal

A quick question without having a deeper look onto the patch (and without testing):

+++ b/js/shs.js
@@ -550,33 +541,47 @@
+    if ($.fn.chosen === void 0 || Drupal.settings.chosen === void 0) {
+      return false;

What does void 0 do? I've never seen this before.

markhalliwell’s picture

I'm not going to play issue status ping pong, but I would consider this a major bug since the stable (and only) release for the Chosen module is the 7.x-2.x branch (major) and the current chosen implementation in this module does absolutely nothing (bug).

What does void 0 do? I've never seen this before.

This is the easiest (and shortest) way to check if a variable is undefined. See: http://stackoverflow.com/a/7452352/1226717

  • stBorchert committed 72234af on 7.x-1.x authored by markcarver
    Issue #2084019 by revagomes, guillaumev, jibize, markcarver, idebr:...
stBorchert’s picture

Status: Needs review » Fixed

Thanks for the work and your patience ;). I've committed the integration for Chosen 2.x.
Chosen 7.x-1.x (and thus Chosen library <1.1.0) is not supported by SHS anymore.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.