Skip Navigation

[Resolved] Chosen Multiselect is not working when page is loaded the first time

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to implement Chosen multiselect box with view's filter

Solution:
You should add custom javascript code to your view's filter section's JS box in order to implement chosen multiselect with view's filters.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/chosen-multiselect-is-not-working-when-page-is-loaded-the-first-time/#post-868443

Relevant Documentation:

This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by Minesh 6 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#864794
Multiselect 2.png
Multiselect 1.png

I am trying to:
Display in a parametric search a multiselect with the chosen ui

Link to a page where the issue can be seen:
hidden link

I expected to see:
The chosen ui multiselect style from the beginning.

Instead, I got:
The select field changes to chosen when I click any filter, search button or reset button.
After i clicked one of the above it's working fine.

Regards
Ben

#867221

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - could you please tell the filter you've added is for custom field or taxonomy field.

What if you try to add following attribute to your filter shortcode you are using: - to disable the select2.

use_select2="never"

Could you please check it that helps, if not, could you please share the code you are using within your view's filter to display that multiselect field.

#867342

Hi Minesh,

it's a taxonomy. Where do i set this option?

At first I integrated chosen manually in my script.js but than i noticed that chosen is already integrated in toolset.
Where can I set the different options for chosen?

Regrads
Ben

#867343

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

We are using select2 JS and there is no option available to customize it.

As said - could you please share the filter code which you are using to display the taxonomy filter?

#867866

HTML Parametric view:

[wpv-control-post-taxonomy taxonomy="lehrinhalt" type="multi-select" format="%%NAME%% (%%COUNT%%)" url_param="wpv-lehrinhalt" class="chosen-select"][php]

At first I added this in the script.js, but it works without it too:

[php]
$(".chosen-select").chosen({
	no_results_text: "Leider kein Treffer!",
	max_selected_options: 5

Toolset types has also chosen in it's libs:

/wp-content/plugins/types/vendor/toolset/toolset-common/res/lib/chosen

but if select2 works better i could use that too.

#867961

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I tried to check with my local test install and I see that the multi-select remains the same.

Now, as I understand, you want to display taxonomy with chosen select when page loads as well as when user change the filter - If this is correct. I need access details so I can try to apply available view's js event hooks.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#868443

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - It looks like when page load we need to initialize the filter again with chosen. So I've added following code as you suggested to view's filter JS box and I can see when page is loaded it by default shows filter with chosen.

jQuery(document).ready(function($){

  $(".chosen-select").chosen({
    no_results_text: "Leider kein Treffer!",
    max_selected_options: 5
   });
  
});
#871327

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please confirm it works for you as well 🙂