Skip Navigation

[Resolved] After reset form lost my JS function

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

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/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by davideE-4 4 years, 5 months ago.

Assisted by: Waqar.

Author
Posts
#1640957

Hi,
i created three function into JS tab of my filter form

First after reset form
$(".js-wpv-reset-trigger").click(function(e) {
// after reset
console.log("Reset");
});
});

Second after change select
jQuery(document).ready(function($){
$('select.my-select').on('change', function(){
console.log("Change value");
});
});

Third after filter data
jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
// after reload data
console.log("Reload data");
});

All three works until I hit reset.
After the reset, no function is called again.
How can I solve it?

Regards

#1642761

Hi David,

Thank you for contacting us and I'd be happy to assist.

The way your custom script blocks have been added, the first two blocks are executed when the page loads/reloads, but not once the results have updated through AJAX.

You can wrap them inside a named function and then make sure that this function is executed on page load/reload ( .ready ) and when the results have updated ( js_event_wpv_parametric_search_results_updated ).

Example:


jQuery(document).ready(function($){
	combinedAction();
});

jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
	// after reload data
	console.log("Reload data");
	combinedAction();
});

function combinedAction() {
	jQuery(".js-wpv-reset-trigger").click(function(e) {
		// after reset
		console.log("Reset");
	});

	jQuery('select.my-select').on('change', function(){
		console.log("Change value");
	});
}

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1642925

My issue is resolved now. Thank you!