Я хочу получить последний выбранный или невыбранный элемент моего select2. Я следовал официальной документации, но ничего не происходит. Это мой код:
jQuery(document).ready(function() {
Main.init();
var $eventSelect = $('.search-select'); //select your select2 input
$(".search-select").select2({
allowClear: true
});
$eventSelect.on('select2:unselect', function(e) {
console.log('unselect');
console.log(e.params.data.id); //This will give you the id of the unselected attribute
console.log(e.params.data.text); //This will give you the text of the unselected text
})
$eventSelect.on('select2:select', function(e) {
console.log('select');
console.log(e.params.data.id); //This will give you the id of the selected attribute
console.log(e.params.data.text); //This will give you the text of the selected
})
$(".search-select").on('select2:select', function(e) {
console.log(e.params.data.id);
});
});
<select id="bird_id_1" name="bird_id_1[]" class="form-control search-select selects" multiple required>
@foreach($birds as $bird)
<option value="{{ $bird->id }}" {{ in_array($bird->id, App\Http\Controllers\ClaimController::getbirdsids($claim->id)) ? 'selected' : '' }}>{{ $bird->title_fr }}</option>
@endforeach
</select>