Coveo "X" Button to Clear Results - Coveo for Sitecore 5

As you may have noticed, Coveo for Sitecore 5 did away with the "X" button clearing the Coveo search results. This was a feature that I thought was very functional and intuitive, but no doubt led to higher query counts, which I'm sure is the reason why they did away with it.

If you wanted to bring that functionality, here's a code snippet that you can put onto your Coveo search page.

    $('.CoveoSearchInterface').on('afterInitialization', function () {
        $(".magic-box-clear").on("click", function (event) {
            var clearButton = $(event.target);
            var searchBox = clearButton.parents('.CoveoSearchbox');
            if (searchBox.length) {
                searchBox.coveo().queryController.executeQuery();
            }
        });
    });

Happy coding!

Add comment