Skip Navigation

[Resolved] Custom Search / Custom text in stead of empty search Criterium

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

Problem:

How to add a value for the search dropdown default item instead of the blank label?

Solution:

Add the Javascript code below to the view:

function setDropdownDefaultValue() {
    jQuery('select[name="wpv-category"] > option:first-child').text('LABEL');
}
jQuery(document).ready(function() {
    setDropdownDefaultValue();
});
 
jQuery(document).ajaxComplete(function() {
    setDropdownDefaultValue();
});

replace LABEL with the label you want to add.

Relevant Documentation:

https://toolset.com/course-lesson/adding-custom-javascript-to-views-templates-and-archives/

This support ticket is created 3 years, 10 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 4 replies, has 2 voices.

Last updated by ronM-3 3 years, 10 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2327465

Hi,

Custom search by category is used on this page: hidden link
By default all news items are shown. The search/filter criterium is empty.

Is it possible to have something like 'All' or 'All news items' instead?

Regards,
Ron

#2328209

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Please add the JS code below to the View at the right sidebar:

jQuery(document).ready(function() {
    jQuery('select[name="wpv-category"] > option:first-child').text('All');
});

There you will be able to change the text to All and you are welcome to change it in the code to whatever text that you want.

For more information on how to add Javascript code to a View:

https://toolset.com/course-lesson/adding-custom-javascript-to-views-templates-and-archives/

Thank you.

#2329871

Hi Cristopher,

Thnx. That helped to initially fill a custom text in the search criterium.

However, after filtering on a category and selecting the dropdown again, the custom text has disappeared.
Do you have a solution for that too?

Regards,
Ron

#2329915

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Yes, it is possible. Please update the Javascript code to the one below:

function setDropdownDefaultValue() {
	jQuery('select[name="wpv-category"] > option:first-child').text('Alle nieuwsberichten');
}
jQuery(document).ready(function() {
    setDropdownDefaultValue();
});

jQuery(document).ajaxComplete(function() {
	setDropdownDefaultValue();
});

Thank you.

#2329989

My issue is resolved now. Thank you!