'use strict'; initSelect2 = (inputs, extra = {}) -> inputs.each -> item = $(this) # reading from data allows to be passed to select2 options = $.extend(allowClear: true, extra, item.data('select2')) # because select2 reads from input.data to check if it is select2 already item.data('select2', null) item.select2(options) $(document).on 'has_many_add:after', '.has_many_container', (e, fieldset) -> initSelect2(fieldset.find('.select2-input')) $(document).on 'ready page:load turbolinks:load', -> initSelect2($(".select2-input"), placeholder: "") return