Sam
Sam

Reputation: 1692

Modify Select2 search box

I am using the ajax feature of the Select2 control to load the options asynchronously. However, I would like to change the default template of the search box to have a placeholder and an icon on the right.

Is there a proper way to do that?

enter image description here

Upvotes: 0

Views: 460

Answers (1)

Pramus
Pramus

Reputation: 430

Placeholder: From the example:

$(".js-example-placeholder-single").select2({
  placeholder: "Select a state",
  allowClear: true
});

Custom Icon:

You can append it using JS. Simply create a DOM element, append it where you want and style it with CSS. Of course you can also add its additional functionality if needed.

http://www.w3schools.com/jsref/met_node_appendchild.asp

Upvotes: 1

Related Questions