Last active
December 27, 2019 05:40
-
-
Save philsmy/f0f52e37ed4913913e2f2e63be67f165 to your computer and use it in GitHub Desktop.
Basics of Select2 and Stimulus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from "stimulus" | |
import $ from 'jquery'; | |
require("select2/dist/css/select2") | |
require("select2-bootstrap-theme/dist/select2-bootstrap") | |
import Select2 from "select2" | |
export default class extends Controller { | |
connect() { | |
$('.subscriber-tags').select2({ | |
tags: true, | |
tokenSeparators: [',', ' '] | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_with(model: @my_model, local: true) do |form| %> | |
<div class='card mt-4'> | |
<div class='card-header'> | |
Tags | |
</div> | |
<div class='card-body' data-controller='select2'> | |
<%= form.select :tags, SubscriberTag.all.map{ |t| [t.name,t.id]}, {include_blank: true, required: false, include_hidden: false}, class: 'form-control subscriber-tags', multiple: 'multiple' %> | |
</div> | |
</div> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment