Skip to content

Instantly share code, notes, and snippets.

@MyklClason
Last active July 23, 2022 22:56
Show Gist options
  • Save MyklClason/66eaa99d224b8a70c1a3cd0203a92c75 to your computer and use it in GitHub Desktop.
Save MyklClason/66eaa99d224b8a70c1a3cd0203a92c75 to your computer and use it in GitHub Desktop.
select2 scripts
<script>
$(document).on('turbolinks:before-cache', function(e) {
$('.form-control.select2, .form-control.select2-taggable, .form-control.select2-w-100').each(function() {
if ($(this).data('select2')) {
$(this).select2('destroy');
}
});
});
$('.form-control.select2, .form-control.select2-taggable, .form-control.select2-w-100').each(function() {
if ($(this).data('select2')) {
$(this).select2('destroy');
}
});
$(document).on('select2:open', () => {
document.querySelector('.select2-search__field').focus();
});
$('.select2').select2();
$('.select2-w-100').select2({
width: "100%",
});
$('.select2-taggable').select2({
tags: true,
width: "100%",
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment