Hello, I've set a view and I want to hide search fields and show them if I check boxes.
I've read and followed: https://toolset.com/forums/topic/setting-up-the-search-portion-of-a-view/
... but it doesn't works.
2 Sections: Text Search and Advanced Search Fields
I would like to don't show filter options by default and show them only if checkboxes are checked
Here Edit View Search Code:
**************************************************
<div class="p-3 mb-2 bg-light text-dark">
<div class="form-group wpcf-search">
<input type="checkbox" id="txtsearch" name="txtsearch" value="1" checked>
<label for="txtsearch">Text Search</label>
<input type="checkbox" id="advsearch" name="advsearch" value="1" checked>
<label for="advsearch">Advanced Search</label>
</div>
<!-- Section for the text search option fields -->
<div id="text-search-container">
<div class="form-group">
<label for="wpv-post-search">[wpml-string context="wpv-views"]Cerca[/wpml-string]</label>
[wpv-filter-search-box output="bootstrap"]
</div>
</div>
<!-- Section for the Advanced Search option fields -->
<div id="advanced-search-container">
....
**************************************************
And this is JS
**************************************************
jQuery( document ).ready(function() {
searchFilterHideFunction();
});
function searchFilterHideFunction() {
jQuery('.text-search-container').hide();
jQuery('.advanced-search-container').hide();
var selectedOptions = [];
jQuery.each(jQuery(".wpcf-search input[type='checkbox']:checked"), function(){
selectedOptions.push(jQuery(this).val());
});
if( selectedOptions.indexOf('txtsearch') >= 0 ) {
jQuery('.text-search-container').show();
}
if( selectedOptions.indexOf('advancedsearch') >= 0 ) {
jQuery('.advanced-search-container').show();
}
}
**************************************************
Custom Search Settings
**************************************************
Let me choose individual settings manually
Update the View results every time an input changes
Javascript settings --> will run after updating the results --> searchFilterHideFunction
Many thanks!!! 🙂