select2.org events
$('#mySelect2').on('select2:select', function (e) {
var data = e.params.data;
console.log(data);
});
select2.org events
$('#mySelect2').on('select2:select', function (e) {
var data = e.params.data;
console.log(data);
});
add image in select2 dropdown
$(".class").select2({
templateResult: formatState,
templateSelection: formatState
});
function formatState (opt) {
if (!opt.id) {
return opt.text.toUpperCase();
}
var optimage = $(opt.element).attr('data-image');
console.log(optimage)
if(!optimage){
return opt.text.toUpperCase();
} else {
var $opt = $(
'<span><img src="' + optimage + '" width="60px" /> ' + opt.text.toUpperCase() + '</span>'
);
return $opt;
}
};
select 2 dropdown
$('#element').select2({
placeholder: 'Select a option',
minimumInputLength: 3,
ajax: {
url: route('api.fetch-options'),
dataType: 'json',
type: 'GET',
quietMillis: 50,
data: function (params) {
return {
visitor_name: params.term
}
},
processResults({ data }) {
return {
results: $.map(data, function (item) {
return {
text: item.name,
id: item.id,
}
})
}
}
}
}).change(() => {
// perform some action on change
});
select 2 dropdown
$(".js-example-basic-multiple-limit").select2({
maximumSelectionLength: 2
});
select2
$(".js-example-basic-multiple-limit").select2({
maximumSelectionLength: 3
});
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us