10/06/2022 2409
Berikut cara menggunakan jquery dan select2 untuk mendapatkan custom atribut jadi ketika mengganti select bos yang terpilih dapat ditampilkan tidak hanya text dan id tapi dengan custom atribut dapat menampilkan dan memparsing ke input lain.. :D
$('.itemsearch').select2({
ajax: {
url: "{{ route('wh.item.search') }}",
dataType: 'json',
delay: 250,
processResults: function(data) {
return {
results: $.map(data, function(item) {
return {
text: item.name,
id: item.id,
"item_price": item.price_sell,
}
})
};
},
cache: true
}
});
$('.itemsearch').change(function(e) {
e.preventDefault();
data = $(".itemsearch").select2('data')[0];
$('.item-price').val(data.item_price);
});
31/10/2020 Tutorial 101749
16/12/2020 Tutorial 21138
12/09/2021 Tutorial 4460
16/10/2020 Tutorial 4189
21/10/2020 Tutorial 3765