Vous avez besoin de jQuery pour utiliser select2.
terminal
yarn add select2
app/javascript/packs/application.js
import 'select2'
import 'select2/dist/css/select2.css'
document.addEventListener('turbolinks:load', () => {
  $('.js-select').select2({
    placeholder: 'Select an option',
    allowClear: true
  })
})
sass
$select2-height: 38px
.select2-container
  .select2-selection--single
    height: $select2-height
    line-height: $select2-height
    .select2-selection__arrow, .select2-selection__rendered
      height: $select2-height
      line-height: $select2-height
  .select2-search--dropdown .select2-search__field
    font-size: 16px
    padding: 4px
Vous avez maintenant introduit select2 dans votre application Ruby on Rails.
selectVers le tagjs-selectCela devrait fonctionner si vous attachez une classe.
Recommended Posts