Sha256: 3ed94b3c72469074e379abb15fd8c0f6054f9b174484dd85d1174815c9b360f0

Contents?: true

Size: 1.26 KB

Versions: 16

Compression:

Stored size: 1.26 KB

Contents

# https://select2.github.io/examples.html

initialize = ->
  $('select.effective_select:not(.initialized)').each (i, element) ->
    element = $(element)
    options = element.data('input-js-options') || {}

    $select = element.addClass('initialized').select2(options)

    # effective_select custom class functionality
    # select2 doesn't provide an initializer to add css classes to its input, so we manually support this feature
    # js_options[:containerClass] and js_options[:dropdownClass]
    $select.data('select2').$container.addClass(options['containerClass']) if options['containerClass']
    $select.data('select2').$dropdown.addClass(options['dropdownClass']) if options['dropdownClass']

$ -> initialize()
$(document).on 'page:change', -> initialize()
$(document).on 'turbolinks:load', -> initialize()
$(document).on 'cocoon:after-insert', -> initialize()

# If we're working with a polymorphic select, split out the ID and assign the hidden _type and _id fields
$(document).on 'change', "select.effective_select.polymorphic", (event) ->
  $select = $(event.target)
  value = $select.val() || ''

  $select.siblings("input[type='hidden'][name$='_type]']").val(value.split('_')[0] || '')
  $select.siblings("input[type='hidden'][name$='_id]']").val(value.split('_')[1] || '')

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
effective_form_inputs-1.0.6 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-1.0.5 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-1.0.4 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-1.0.3 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-1.0.2 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-1.0.1 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-1.0.0 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-0.9.8 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-0.9.7 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-0.9.6 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-0.9.5 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-0.9.4 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-0.9.3 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-0.9.2 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-0.9.1 app/assets/javascripts/effective_select/initialize.js.coffee
effective_form_inputs-0.9.0 app/assets/javascripts/effective_select/initialize.js.coffee