i have barcode scanner i want whenever submit barcode auto select and after than automatically clear the search box
<script>
$(document).ready(function() {
$('.js-example-basic-single1').select2();
$('.js-example-basic-single1').select2('open');
$('.js-example-basic-single1').on('change', function (e) {
@this.set('item_id', e.target.value);
$(this).select2('positionDropdown', true);
$(this).select2("val", "");
});
});
});
</script>
<select autofocus class="form-control js-example-basic-single1" id="js-example-basic-single1" data-allow-clear="true" wire:submit.prevent="item_id" id="item_id">
<option value="{{$item_detail->id}}-1">{{$item_detail->item->id}}-{{$item_detail->item->title}}-{{$item_detail->item->barcode}}</option>
</select>```
With select2, you need to clear it and then trigger the change. This can be done using the library within your function above like so:
$(this).val(null).trigger('change');
That excellent library has pretty decent docs, including for the above question