0

We are using Shareoint 2016 on Prem. Any suggestion on how to set default focus on the Apply Filters button webpart on a Sharepoint site page? So pressing the Enter key will trigger the Apply Filters button. Our users just want to hit the Enter key instead of clicking on the Apply Filter button.

Thanks

  • Jean, if the below solution works for you please click the green checkmark. Thank you – SP-Kyle Aug 1 '19 at 15:41
0

Solution:

https://jsfiddle.net/q0g7ot8y/

More details below:

  1. Create a .html file in site assets called whateveryouwant.html

  2. In the file put the code from the javascript section (from the jsfiddle Link above), of course replacing whatever class or ID your button has

NOTE: you may need to surround the javascript code in whateveryouwant.html with (see example at bottom of this answer). Also if you aren't already loading jQuery on the page you may need to in the whateveryouwant.html file

  1. Then simply add a Content Editor Web Part to the page and point the content editor to your whateveryouwant.html file

  2. This should focus the page onto the selected button. Look at the JS FIDDLE example, my button is ID yourButtonID in the html section and so in the JS section I look for #yourButtonID. Change this to fit your buttons class or ID

Side Note: You could try and do this in a snippet webpart but I have seen more consistent results doing it as described above.


whateveryouwant.html example:

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

 <script type="text/javascript">
  $(document).ready(function(){

        //This will set the focus to the button based on its ID
        $('#yourButtonId').focus();

      //This code below is simply to alert and show you that when you press enter.... it then fires the alert window, remove all this code below for your final file
      $('#yourButtonId').on('keypress',function(e){
      if(e.which == 13) {
            alert('You pressed enter!');
        }
      })
      //End test code for alert

    });
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.