Smith Dwayne
Smith Dwayne

Reputation: 2807

Select2 Jquery remove searching term after selecting an item

I am using Jquery Select2 plugin for Multi Select Dropdown with Check box by referring the below code pen link.

Ref:Please find this [codepen link][1]

https://codepen.io/faur/pen/vWVPGE

When I search for Options List as 'opt' and choosing the element from the Elements. After the selection, my searched term 'opt' still showing in the input box. I want to clear the searched text after selecting the element. How Can I do that?

enter image description here

Upvotes: 2

Views: 1588

Answers (1)

ChiaraL
ChiaraL

Reputation: 31

I had the exact same problem with Select2 Version 4.1.0-beta.1 and I searched for a long time, then I found this solution which use the generic selector for the select and at the time of selection it clears the value of the search__field. For me it worked perfectly. Hope it will work for you too:

    $("select").on('select2:select', function (e) {
     $('.select2-search__field').val('');
    });

Upvotes: 3

Related Questions