Wednesday 14 October 2015

TypeError: this.form_*.options is undefined */sites/all/libraries/chosen/chosen.jquery.min.js?v=1.1.0 Line 2

This post is relevant to Drupal 7 chosen module and using Views and having an exposed filer.

So using Pages to set this up the first dropdown list wasn't displaying correctly .  And in Firebug error I could see the message

TypeError: this.form_*.options is undefined */sites/all/libraries/chosen/chosen.jquery.min.js?v=1.1.0 Line 2

What made this even stranger is that when calling the panel for the exposed filter again on the page the second version works fine.  Swap them around and it's always the top one that fell down.

In the end I found the code at fault in a customized file in themes.



 if (typeof $selects.chosen === 'function' && categoryLocation !== 'client-stories' ) {

        $selects.chosen({ 

          disable_search_threshold: 1,

          placeholder_text_multiple: 'Choose options',

          placeholder_text_single: 'Choose'

        });

      } 

A temporary fix was to ignore for the page I was on.  But does anyone know why the issue is occurring , I'd love to know.  Here's my fix .


             // an issue with the dropdown on 'client-stories' that's linked to this page - going to ignore this code for that page

        // 1. lets get the folder we're in.



        var pathArray = window.location.pathname.split( '/' );

        var categoryLocation = pathArray[1];

        // 2. and ignore the following if we are on the client-stories page .



      if (typeof $selects.chosen === 'function' && categoryLocation !== 'client-stories' ) {

        $selects.chosen({

          disable_search_threshold: 1,

          placeholder_text_multiple: 'Choose options',

          placeholder_text_single: 'Choose'

        });

      }



No comments: