Want select2 not to select first option by default

27,564 views
Skip to first unread message

pratee...@gmail.com

unread,
Jun 3, 2016, 3:51:36 PM6/3/16
to select2
HI Folks,

I am using select2 library over a search bar. What happens is when the search results appear in the drop-down as list select2 automatically gives first option as selected, which I don't want.

I want no option to be selected by default instead want to get it selected whenever the user presses and up/down arrow key after the results appear.

Can some-one please help me in achieving this ?

Thanks.

bruno.m...@gmail.com

unread,
Aug 16, 2016, 6:58:46 PM8/16/16
to select2, pratee...@gmail.com
This is not an answer at all and i'm sorry for this false hope but an answer would surely help me too !

Kevin Brown

unread,
Aug 16, 2016, 9:34:55 PM8/16/16
to select2, pratee...@gmail.com

This behaviour exists not because Select2 is forcing it, but because the browser is auto-selecting the first option for you. We can't control that, we can only work around it. Your best option is to use the placeholder support in Select2 and include a blank option tag as your default selection.


On Tue, Aug 16, 2016, 18:58 <bruno.m...@gmail.com> wrote:
This is not an answer at all and i'm sorry for this false hope but an answer would surely help me too !

--
You received this message because you are subscribed to the Google Groups "select2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to select2+u...@googlegroups.com.
To post to this group, send email to sel...@googlegroups.com.
Visit this group at https://groups.google.com/group/select2.
For more options, visit https://groups.google.com/d/optout.

bruno.m...@gmail.com

unread,
Aug 17, 2016, 6:14:48 AM8/17/16
to select2, pratee...@gmail.com
Thanks ! :D

jp3...@gmail.com

unread,
Feb 15, 2018, 11:03:12 AM2/15/18
to select2
// This may help some one although this is an old post.

$('#keywordselect').select2({
placeholder: 'Select...',
closeOnSelect: false,
multiple: true,
});

// one clears the box content and the other clears the highlighting
$('#keywordselect').val(null);
$('.select2-selection__rendered').html('');

jaji...@gmail.com

unread,
Jul 26, 2018, 3:54:08 PM7/26/18
to select2

bharath...@gmail.com

unread,
Aug 1, 2018, 5:42:03 AM8/1/18
to select2

add empty option to top of the <select> tag . Do this before intialization
<option></option>

mikibe...@gmail.com

unread,
Dec 10, 2019, 5:04:32 AM12/10/19
to select2
If its still relevant to someone, here's the fix:

  $("#yourelementid").select2({ [options]... });

  ..
  $("#yourelementid").val("")
  $("#yourelementid").trigger("change");

Joost Roetgering

unread,
Sep 26, 2022, 4:13:02 AM9/26/22
to select2
For anyone that still needs it. If you add multiple="multiple" to the select element it won't auto select the first option. For example:

<select class="select-class"  multiple="multiple">
<option value="value">value</option>
</select>
Op vrijdag 3 juni 2016 om 21:51:36 UTC+2 schreef pratee...@gmail.com:

Sumit Pradhan

unread,
Oct 12, 2022, 4:53:12 AM10/12/22
to sel...@googlegroups.com
Thank you for your response.

Best of Regards,
Sumit Pradhan
Cell: 9841960029


--
You received this message because you are subscribed to the Google Groups "select2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to select2+u...@googlegroups.com.

sumit khatri

unread,
Jan 17, 2023, 2:50:39 AM1/17/23
to select2
If you are working on change events,


you can use $("#select").val(0);
untill you donot have option with val=0;

२०२२ अक्टोबर १२, बुधबार का दिन १४:३८:१२ UTC+5:45 बजे pradhan...@gmail.com ले यस्तो लेख्नुभयो:

Emma Snow

unread,
Dec 21, 2025, 8:19:07 AM (17 hours ago) Dec 21
to select2

Thirty one Products offers a wide range of high-quality items designed to simplify daily life and enhance personal style. From practical essentials to stylish accessories, their products combine functionality with modern design. With Thirty one Products, you can enjoy reliable, well-crafted items that make everyday tasks easier and more enjoyable.

Reply all
Reply to author
Forward
0 new messages