jquery select plugin code example
Example: jquery select plugin
//place css in head
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
//Place it before closing body tag above the below code
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
//script below should be placed before body closing tag or in seprate script file
<script>
$(document).ready(function() {
function matchCustom(params, data) {
if ($.trim(params.term) === '') {
return data;
}
if (typeof data.text === 'undefined') {
return null;
}
if (data.text.indexOf(params.term) > -1) {
var modifiedData = $.extend({}, data, true);
modifiedData.text += ' (matched)';
return modifiedData;
}
return null;
}
$(".search-select").select2({
matcher: matchCustom
});
});
</script>
//Customizing the css are these classes
// This is for input
.select2-container--default .select2-selection--single {
background-color: #ebebeb;
border-radius: 10px;
padding: 14px 24px 14px 24px;
border: 1px solid #dcdee1;
color: #73777fb3;
min-height: 57px;
width: 100%;
font-size: 18px;
}
//This is for arrow position
.select2-selection__arrow {
top: -7px;
margin-top: auto;
margin-bottom: auto;
bottom: 0;
right: 15px !important;
}