ClearAll widget?

Is there any ClearAll() widget in v 3.4? I need a button to clear all refinements, Geosearch and Searchbox query at the same time. Thank you.

Hi there!

There is no widget that clears everything you mention. We do have a clearRefinements widget. This is a widget that, when clicked, will remove all the current refinements. In order to clear the query, you could leverage the transformItems function of the clearRefinements widget, which gets called as soon as it’s clicked. From there, you could remove the query from your searchbox, kind of like this:

instantsearch.widgets.clearRefinements({
  transformItems(items) {
    $('#yourSearchInput').value = '';
    return items;
  },
});

Hope this helps!

Thank you for your answer, but the the transformItems event not only fires when the button is clicked.
But I can add “query” in the ‘includedAttributes’ option. It works well.

I have another problem, I have a custom widget that I created for the user to be able to filter results based on his location. The widget works as expected, but I cannot add it to ‘includedAttributes’.

Here is the code of the custom widget :

{
    init(opts) {
        const helper = opts.helper;
        const input = document.querySelector('#select-around-me');
        input.addEventListener("change", function() {
            if(input.value === 0){
                helper.setQueryParameter('aroundLatLng');
                helper.setQueryParameter('aroundRadius').search();
            } else {
                navigator.geolocation.getCurrentPosition(function (position) {
                    var latLng = position.coords.latitude+', '+position.coords.longitude;
                    helper.setQueryParameter('aroundLatLng', latLng);
                    helper.setQueryParameter('aroundRadius', input.value) // update the parameters
                    .search(); // launch the query
                });	
            }
        });
    },
},

How i can name my custom widget to add it in my includedAttributes option?

Thank you

Hi there,

Good to hear that you figured it out!

Regarding your other problem, I think you can add both aroundLatLng and aroundRadius to your list of includedAttributes, and it should reset both query parameters. Let me know if this works!

Cheers,
Devin.

Unfortunately this doesn’t work with aroundLatLng and aroundRadius as includedAttributes…

Hi there,
I’ve come up with a different approach.


From the code sandbox above, I’ve created a widget with a connector connectClearRefinements.
It leverages the function of connectClearRefinements (which is refine function).
If you see instantsearch() function, I added searchFunction method which is executed right before every search.
There I added some code to get rid of aroundLatLng and aroundRadius.

I hope this works for you.
Let me know how it goes and if you have any question.