Autofoucs on search input in select


Topic: Autofoucs on search input in select

razakkm asked 4 years ago

I am using searchable select field with more than 100 options. Can you please tell me how to focus on the search input field when we click on the select.


Grzegorz Bujański staff commented 4 years ago

Unfortunately, we do not support this option. You can write your own function which after clicking on select will set focus to search input.


razakkm commented 4 years ago

I have tried writing on click event, but it is not working. Can you please share the code to do that?


Grzegorz Bujański staff commented 4 years ago

Why are you trying to apply such a solution? To be able to start searching immediately? You do not have to do anything. Just start typing and the search will start automatically


razakkm commented 4 years ago

It is not intuitive, most of the users come back and ask can you provide search option. We have to tell them it is already there, instead can we do autofocus on the search input field as soon as they click on the select field.


Grzegorz Bujański staff answered 4 years ago

I understand. You can try this solution:

$(document).ready(function() {
    $('.mdb-select').materialSelect();

  $('.select-dropdown').on('click', () => {
    $('.mdb-select').find('input.search').focus();
  })
});

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.17.0
  • Device: Laptop
  • Browser: Chrome
  • OS: Mac OS
  • Provided sample code: No
  • Provided link: No