I just updated to 7.x-2.0-alpha4, and now when using chosen on a taxonomy field that has hierarchy, I cannot search the items in a lower category. It only searches the top level listings.
I tried to revert back but I guess it updated my database already so nothing changed.
How can I fix this?

Comments

hydra’s picture

Don't worry, nothing happended to you database, chosen only does frontend stuff. So nothing is lost. I will have a look into it later, thanks for reporting this.

eric_a’s picture

Version: 7.x-2.0-alpha4 » 7.x-2.x-dev
Issue summary: View changes

I just noticed this in 7.x-2.0-alpha4+7-dev. I get results if I add the depth character myself, but I don't always know which level to search :-)

I just updated to 7.x-2.0-alpha4, and now when using chosen on a taxonomy field that has hierarchy, I cannot search the items in a lower category.

@surfkid, which version did you update from?

adshill’s picture

Yeah this is because it includes the dash in the taxonomy heirachy. It works if you type in "-term" which is not really useful.

Thus the module unfortunately is not ready for heirachical taxonomy. If I were a programmer I'd try and fix it, but I'm afraid I'm not :(

nsshrinivasan’s picture

I had to identify the items within a hierarchy that starts with "-" which indicates a sub level and then use the rest of the text to do the search string match.

Here is what I added to the search_string_match function:

  while(search_string.charAt(0) === '-')
        search_string = search_string.substr(1);

Here is the context of where it fits into:

AbstractChosen.prototype.search_string_match = function(search_string, regex) {
      var part, parts, _i, _len;
      while(search_string.charAt(0) === '-')
        search_string = search_string.substr(1);

      if (regex.test(search_string)) {
        return true;
ben.bunk’s picture

The above change is in the chosen jquery plugin. Hopefully there is another way to address this.

nsshrinivasan’s picture

There is a configurable option that is available in the jquery chosen plugin library called "search contains", documentation is available here http://harvesthq.github.io/chosen/options.html. This configuration can be configured via Configuration -> Chosen -> Search also in the middle of words option which allows to search text anywhere in the word(as opposed to "starts with" search).

margyly’s picture

I need this, too. Otherwise I have to tell my users to type a "-" to see what values are in the second level of the hierarchy. Wish I could fix it!

batigolix’s picture

Status: Active » Reviewed & tested by the community

nsshrinivasan's suggestion to check "Search also in the middle of words" at Configuration > Chosen > Search works perfectly.

batigolix’s picture

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