Skip Navigation

[Resuelto] Prevent Search from being triggered

This support ticket is created hace 7 años, 3 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

Este tema contiene 16 respuestas, tiene 2 mensajes.

Última actualización por Luo Yang hace 7 años, 2 meses.

Asistido por: Luo Yang.

Autor
Mensajes
#562967

I added the following on my custom filter to make a selection required, the alert works, but inside the if statement I need to prevent the results from refreshing/updating?

[code]
jQuery( document ).on( 'js_event_wpv_parametric_search_started', function( event, data ) {

var inc = 0;
jQuery('[name="wpv-payment"]').each(function () {
if (jQuery(this).is(':checked')) inc++;
});
if (inc == 0) {
alert('Please Choose a payment type');
}

});
[/code]

#563018

Dear nicholas,

Since it is a custom JS codes question, I need to duplicate same problem and debug the codes in my localhost:
How do you setup the custom field "wpv-payment"? is it a custom checkboxes field?
How do you setup the custom search form of the view? Are you using the setting "AJAX results update when visitors click on the search button"?

#563755

wpv-payment is a Radio button filter with no default option added. Yes I am using "AJAX results update when visitors click on the search button"? So I just need to add a bit of code to that script that will prevent the AJAX from reloading.

#564068

Please try to modify your JS codes as below:

jQuery( "input.wpv-submit-trigger" ).click(function(e) {
  
	var inc = 0;
	jQuery('[name="wpv-payment"]').each(function () {
		if (jQuery(this).is(':checked')) inc++;
	});
	if (inc == 0) {
		alert('Please Choose a payment type');
		return false;
	}
  	return;
});

More help:
enlace oculto
Bind an event handler to the "click" JavaScript event, or trigger that event on an element.

#564406

This appears to do the same thing, the alert is fired on click of submit button, after hitting ok your results still update. I need to prevent the Ajax search results from updating on submit I need to break the "js_event_wpv_parametric_search_triggered" function if the select isn't checked.

#564418

one thought I had was to create my own submit button shortcode that runs my check function and triggers the ajax function if is :checked ?

#564525

I tested above JS codes in my localhost, it works fine, since it is a custom JS codes question, please provide a test site with same problem, also point out the problem page URl and View form URL, I need to test and debug it in a live website, thanks

#564540

I can send you login credentials to a dev server, how do I send that hidden to public?

#564541

I have enabled the "private detail box", please please provide a test site with same problem, also point out the problem page URl and View form URL, I need to test and debug it in a live website, thanks

#564573

Thanks for the details, I am checking it in your website, will feedback if there is anything found

#564582

You are right, the JS codes does not work in your website, but "js_event_wpv_parametric_search_triggered" works like an action, it will not be able to prevent the Ajax search results from updating on submit.

I tried the thought you mentioned above:
https://toolset.com/forums/topic/prevent-search-from-being-triggered/#post-564418
thought I had was to create my own submit button shortcode that runs my check function and triggers the ajax function if is :checked ?

Here is detail steps
1) Edit the view, in section "Filter Editor", display another button, and hide the submit button:

<div class="FilterSubmit"><button class="my-submit-trigger" name="wpv_filter_submit1">Submit</button><span style="display:none;">[wpv-filter-submit]</span></div>

2) Modify the JS codes as below:

  jQuery(document).on('click', 'button.my-submit-trigger', function(e){
  
  
    var inc = 0;
    jQuery('[name="wpv-payment"]').each(function () {
      if (jQuery(this).is(':checked')) inc++;
    });
  
    if (inc == 0) {
      alert('Please Choose a payment type');
      e.preventDefault();
    }
  
   jQuery('input.my-submit-trigger').click();
  
  });

Please test again, check if it is what you want. and you will need to style the button manually.

#565964

Ok, this works great and I am able to expand it for what I need as a final solution, however I have one issue this has caused. I have some scripts running inside the js_event_wpv_parametric_search_results_updated function, and these are not triggered with the new button. I added a simple Alert in the view inside this function for you to see, it will run on reset but not on the new button. How can we make sure this function runs with our new button?

#566289

You will need to enable the AJAX parameter search feature of the view, for example, edit the view "Care Assist", in section "Custom Search Settings", change the option "When to update the Views results" from:
Reload the page to update the View results
To:
Update the Views results without reloading the page

It will trigger the event "js_event_wpv_parametric_search_results_updated "

#566919

This is what the setting is set at, If you login you will see this and the js alert I added in the view, however the event is only running on reset not using our new submit button.

#567077

I have modified the JS codes to below:

jQuery(document).on('click', 'button.my-submit-trigger', function(e){
    var inc = 0;
    jQuery('[name="wpv-payment"]').each(function () {
      if (jQuery(this).is(':checked')) inc++;
    });
  
    if (inc == 0) {
      alert('Please Choose a payment type');
      //e.preventDefault();
      return false; // added this line
    }
  
   jQuery('input.wpv-submit-trigger').click();
  }); 

Please test again, check if it is fixed or not, thanks