Skip Navigation

[Resolved] Trigger a query update when filter updated with code

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 11 replies, has 2 voices.

Last updated by Minesh 1 year, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2570035

I am trying to add a "switch" that sets the value of a filter to update the results.

In my view, I have the following filter:
'''
[wpv-control-postmeta field="nkd-ticket-status" type="select" default_label="-- availability --" format="%%NAME%% (%%COUNT%%)" url_param="ticketstatus"]
'''
I have added the following javascript:
'''
<script type="text/javascript">
// dropdown
// soldoutswitch
//
function soldoutswitchTrigger(checked)
{
var ticketstatusDropDown = document.getElementById("wpv_control_select_nkd-ticket-status");
if (checked)
{
ticketstatusDropDown.selectedIndex = 0;
} else {
ticketstatusDropDown.value = "Available";
}
ticketstatusDropDown.onchange();
//wpv-filter-48137
jQuery('form[name="wpv-filter-48137"]').first().trigger("change");
//alert("triggered" + checked);
}
</script>
'''
I want to be able to change this with javascript and then trigger an ajax reload. However, when I push the change with the javascript below the dropdown changes, the search results do not reload.

*How do I trigger the search results to reload based on a change to the form?*

#2570109

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

There should be change event for the dropdown you will actually have to fire but let me first review your current setup.

Can you please share problem URL and steps that I need to follow and tell me on what action you want to fire the change event and also share admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2570123

Minesh,

Can you tell me the javascript to call that will trigger the submission of the custom query filters?

This question should not require access to anything to answer.

Page: hidden link

See "Experiment2"! Flipping the switch updates the drop down, but does not trigger a refresh.

#2570131

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Toolset offers various frontend event hooks that you can use as per your requirement.

More info:
- https://toolset.com/documentation/programmer-reference/adding-custom-javascript-code-to-views-that-use-ajax/

Please check the following related ticket:
- https://toolset.com/forums/topic/is-there-a-list-of-frontent-events/#post-1207853

#2570301

There is nothing on either link about triggering the custom query. Only about reacting to an already triggered query.

Can you tell me the javascript to call that will trigger the submission of the custom query filters?

#2571881

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I can offer you the sandbox site where you can implement the test demo and tell me what you want to filter and trigger and on what action.

Here is the sandbox site and you can auto-login to it using the following link:
- hidden link

Either you can create a test demo with the above sandbox site or send me admin access details to your site with problem URL and tell me on what action you what to fire what event.

I need that because I'll not be sure above HTML elements added to your page or how your custom code works.

I have set the next reply to private which means only you and I have access to it.

#2572581

Minesh

I am not asking a custom question about my implementation. Im asking a product question about Toolset AJAX views.

If I want to trigger a refresh/submission of the filters from outside of the view what javascript do I call to trigger it?

#2572593

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I just understand that you want to call a "change" event using the custom Javascript but what I want is for what kind of field and on what course of action.

I can see you have select dorpdown box added a filter. Do you want to trigger change event for that select dropdown filter? If yes, but on what action you want to automatically trigger the dropdown change event?

If you can share all those information or exact steps on what steps you want to call the select dropdown change event then I will create a demo for you and share with you. If you agree I can add a button and on button click I will call the select dropdown change event - is that ok for you or you want something else?

#2572597

I am able to submit the from with:

jQuery('form[name="wpv-filter-48137"]').first().submit();

But this refreshes the whole page.

How do I trigger a toolset view ajax refresh?

#2572599

I was able to resolve this by calling the change event on the field after using the code to change the value.

jQuery('#wpv_control_select_nkd-ticket-status').first().trigger("change");

#2572601

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

To make your view ajax filtered you will have to set your view to be ajax filtered.

As you can see with the following doc:
- https://toolset.com/documentation/legacy-features/views-plugin/front-page-filters/#custom-search-form
Step : B. Choose how the search behaves

Where you can set your desired option (in your case with AJAX) form your view's "custom search" settings:
- hidden link

If you view is set to AJAX refresh it will work accordingly when you submit the form.

#2572603

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

ok resolved by user.