How to add Custom message into Select2

In this tutorial i will tell you how to add user defined message into select2 control. The Default message of select2 is 'No matches found'. Sometimes we need to add custom message for select2.In this tutorial i will share script for set custom message as well as fire an event on this message.

Also checkout other tutorials of select2,

Step 1: we will add custom option for default option.

Above code will show you ‘Add New Number’ text when you will render select2.

Step 2: Now we will add condition to show above option, when the search match string does not found instead of default message.

}
Step 3: Remove this option at the time of select2 binding.

So ‘Add New Number’ will not show when the first time select2 render, it will show when the matching character does not find.

Step 4: Full code.

Step 5: Result.

custom search message

Demo and Download Source Code Of Select2