[Resolved] Live search results links broken in primary nav

Home Forums Support [Resolved] Live search results links broken in primary nav

Home Forums Support Live search results links broken in primary nav

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1310027
    Steven

    We’re using SearchWP to provide live search results. When we use the search box on a search results page, the live search results drop-down list of links works. When we try to do the same using the primary nav search box on desktop and mobile, the links have to be clicked twice to work. The first click makes the search box disappear (the live search results list remains visible) and the second click activates the link. We tried leaving just the following in our functions.php file and removing everything else along with any CSS in our child theme.

    <?php
    add_filter( 'generate_navigation_search_output', 'tu_nav_live_search' );
    function tu_nav_live_search() {
        printf(
            '<form method="get" class="search-form navigation-search" action="%1$s">
                <input type="search" class="search-field" value="%2$s" name="s" title="%3$s" data-swplive="true" />
            </form>',
            esc_url( home_url( '/' ) ),
            esc_attr( get_search_query() ),
            esc_attr_x( 'Search', 'label', 'generatepress' )
        );
    }

    Using Search WP Version 3.1.13, Search WP Live Ajax Search Version 1.4.6.1, and GP Version 1.10.0.

    #1310407
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    That first click is the javascript closing the navigation search when clicked outside of itself. It’s actually a feature as we didn’t think of search fields like this when developing it.

    Looking at the code, there isn’t much we can do about it right now, unfortunately.

    This is the offending code: https://github.com/tomusborne/generatepress/blob/2.4.2/js/navigation-search.js#L86-L96

    You could manually remove it from the parent theme (you’d need to minify the file and replace the .min.js file).

    Then in the next version, we can at least make it a named function so the event listener can be removed if necessary.

    #1311543
    Steven

    Thanks for the quick diagnosis Tom. It’d be great to have WP Live Ajax search supported in the GP search bar in a future release. It looks like adding the following fixes it for our use case.

    if ( document.querySelector( '.navigation-search.nav-search-active' ) && ! document.querySelector(".searchwp-live-search-results-showing") )

    There’s probably a better way to ensure those without live search enabled aren’t adversely affected. As always, we appreciate the great customer service ๐Ÿ˜‰

    Have a great week!

    #1311813
    Tom
    Lead Developer
    Lead Developer

    Beauty – I’ll look at adding that. Thanks! ๐Ÿ™‚

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.