Skip Navigation

[Resolved] Views: Pre-select checkbox in custom search

This support ticket is created 5 years, 3 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.

This topic contains 1 reply, has 1 voice.

Last updated by webD-3 5 years, 3 months ago.

Author
Posts
#1338187

My view is using Custom Search with a taxonomy filter.

I would like to pre-select one of the five taxonomies when the page is originally loaded.

In the JS editor for Search and Pagination I've added the following:

jQuery("#channel-group-group-none").prop("checked", true);

When the page is originally loaded the box is checked, but the output is not filtered.

Once one clicks on another checkbox, however, the filter is applied and both checkboxes are honored by the filter.

I tried using the options in "Frontend events" but none of them allow me to pre-filter the view upon the initial page load. Is there a way that I can have the initial page load show only the posts that match channel-group-group-none ?

#1338219

I believe I solved my own issue. This seems to work:

jQuery(document).ready(function(){
jQuery("#channel-group-group-none").click();
});

Perhaps making "jQuery(document).ready(function()" available in the "Frontend events" options would be beneficial.

Separately I learned I needed to use .click() instead of .prop("checked", true); in order to actually have the filter applied.