Saltar navegación

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

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

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 4 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.

Este tema contiene 4 respuestas, tiene 2 mensajes.

Última actualización por ronM-3 4 years, 3 months ago.

Asistido por: Christopher Amirian.

Autor
Mensajes
#2327465

Hi,

Custom search by category is used on this page: enlace oculto
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
Colaborador

Idiomas: Inglés (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
Colaborador

Idiomas: Inglés (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!