• I have an odd situation in a plugin I have authored

    in functions file :

    add_action( ‘wp_enqueue_scripts’, ‘bsp_enqueue_search’ );

    function bsp_enqueue_search() {
    wp_enqueue_script( ‘bsp_enqueue_search’, plugins_url(‘js/bsp_enqueue_search.js’,dirname( __FILE__ )) );
    }
    The bsp_enqueue_search.js’ file is

    jQuery(document).ready(function($) {
    	 
       $('#bsp_search_submit1').click(function() {
    		$('#bsp_search_submit1').hide();
    		$('#bsp_search_submit2').show();
    		
    
       });
             
     });

    If you go to

    https://gos.rewweb.co.uk/index/search/

    This has the bbpress search and a wordpress search.

    and click the bbpress search in the body, then ‘searching’ with a spinner appears. If you click the same in the sidebar ‘Search Forums’ it does not, but it is the same form being called, and all the code is there if you inspect, but the js is clearly not being implemented.

    But if you click the WordPress search first, and then click the ‘search forums’ it works

    Can anyone assist is resolving – is it some load order issue?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You’ll have to show us a page with the issue and not a page that requires us to log in.

    Thread Starter Robin W

    (@robin-w)

    Grave apologies – now link works without login

    https://gos.rewweb.co.uk/index/search/

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    It works for me, after submitting the “Search Forums” button in the sidebar the spinner inside the form of the main content (underneath the breadcrumb) is then shown. This is what the code says it will do. What are you expecting to happen?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Edit I’m sorry, I changed the IDs in the above. I have a suspicion that jQuery won’t work if elements have the same ID because this isn’t valid HTML. Try a different ID and you should see the code working.

    Thread Starter Robin W

    (@robin-w)

    Thanks for your response, and for you help so far, which is much appreciated.

    If you load the page and then if you start by clicking the search in the ‘search forums’ – it does not display the ‘searching’ and spinner. But if you click the ‘wordpress search and then click the search forums you will see what I want search forums to do in the sidebar to do.

    Thanks again for looking at this

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Does the issue persist after using unique IDs?

    Thread Starter Robin W

    (@robin-w)

    sorry, don’t quite understand.

    Can you tell me which ID(s) you changed to make this work – I think I am being thick.

    Thanks again for your help.

    Thread Starter Robin W

    (@robin-w)

    and the spinner should display in the sidebar widget.

    so if you click wordpress search, and then once that has rendered click the widget search, you will see what I want to happen, but without having to have clicked the wordpress search.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Js not working in sidebar/widget’ is closed to new replies.