Currently wpv-pagination-embedded.js listens to it's own 'js_event_wpv_parametric_search_triggered' event and may force a parametric form update if the output results will be updated (see line 2615-2635).
It does this ... "to update the pagination links it contains to be in sync with the new results, and default to page 1" (per comments in the source file).
However, any other listener (user code) attached to the 'js_event_wpv_parametric_search_triggered' event will not be aware of the fact that form data was force updated by the internal event handler. The user code will see the original event which will not have force_form_update set in data.
This could cause a logic error in user code (it can't be known how/what user code does with this flag so no assumption should be made about the side effects).
To ensure that user code gets the correct state of force_form_update wpv-pagination-embedded.js should ensure the force_form_update flag that user code sees is set according to what is actually done inside wpv-pagination-embedded.js.
To accomplish this one solution will be to introduce a new event 'js_event_wpv_parametric_search_pre_trigger' which the internal code will listen to prior to then triggering the 'js_event_wpv_parametric_search_triggered' event with the correct setting of force_form_update.
The implementation would be to replace 'js_event_wpv_parametric_search_triggered' with 'js_event_wpv_parametric_search_pre_trigger' in lines 2555, 2562, 2570 2580 and 2609.
Then replace line 2615-2635 as follows:
$( document ).on( 'js_event_wpv_parametric_search_pre_trigger', function( event, data ) {
var defaults = {
force_form_update: false,
force_results_update: false
},
settings = $.extend( {}, defaults, data );
// When the form is not forced to be updated, but the results will be updated, and the layout has pagination
// we need to force update the form too, to update the pagination links it contains to be in sync with the new results, and default to page 1
if (
settings.force_form_update == false
&& (
settings.force_results_update == true
|| settings.form.hasClass( 'js-wpv-ajax-results-enabled' )
) && _.has( WPViews.view_pagination.paged_views, settings.form.data( 'viewnumber' ) )
&& _.has( WPViews.view_pagination.paged_views[ settings.form.data( 'viewnumber' ) ], 'has_controls_in_form' )
&& WPViews.view_pagination.paged_views[ settings.form.data( 'viewnumber' ) ].has_controls_in_form == 'on'
|| settings.form.hasClass( 'js-wpv-dps-enabled' ) // (BA) If the form has dependencies also flag force_form_update
) {
settings.force_form_update = true;
}
$( document ).trigger( 'js_event_wpv_parametric_search_triggered', [ { view_unique_id: data.view_unique_id, form: data.form, force_form_update: settings.force_form_update, force_results_update: settings.force_results_update } ] ); // (BA) Use value determined above
self.manage_changed_form( settings.form, settings.force_form_update, settings.force_results_update );
});
The alternative would be to replace all the jQuery triggers with a direct function call to the single function that will eventually issue the jQuery trigger event 'js_event_wpv_parametric_search_triggered'.
I've implemented and tested solution #1 and verified correct behavior.
Regards,
Bob