Sha256: 385a608e32c313d1bd02717efccb65e742b08aedc42885537b79350dc319f1d1

Contents?: true

Size: 1.67 KB

Versions: 50

Compression:

Stored size: 1.67 KB

Contents

# Disable dropdown opening when clicking the clear button
# http://stackoverflow.com/questions/29618382/disable-dropdown-opening-on-select2-clear

$(document).on 'select2:unselecting', (event) -> $(event.target).data('state', 'unselected')

$(document).on 'select2:open', (event) ->
  $select = $(event.target)

  if $select.data('state') == 'unselected'
    $select.removeData('state')
    setTimeout ( => $select.select2('close') ), 0


# effective_select custom reinitialization functionality
# This is a custom event intended to be manually triggered when the underlying options change
# You can use this to dynamically disable options (with or without the effective_select hide_disabled: true)
# https://github.com/select2/select2/issues/2830

# To trigger this event,
# $(document).on 'change', "select[name$='[something_id]']", (event) ->
#   ...add/remove/disable this select field's options...
#   $(event.target).select2().trigger('select2:reinitialize')

$(document).on 'select2:reinitialize', (event) ->
  $select = $(event.target)

  # Get the existing options and value
  options = $select.data('select2').options.options['inputJsOptions'] || {}
  value = $select.find('option:selected').val()

  # Clear/Restore the value appropriately
  if value && $select.find("option:enabled[value='#{value}']").length > 0
    $select.val(value)
  else
    $select.val('')

  # Reinitialize select2
  $select.select2('destroy').select2(options)

  # Restore effective_select custom class functionality
  $select.data('select2').$container.addClass(options['containerClass']) if options['containerClass']
  $select.data('select2').$dropdown.addClass(options['dropdownClass']) if options['dropdownClass']


Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
effective_form_inputs-1.1.9 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.1.8 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.1.7 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.1.6 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.1.5 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.1.4 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.1.3 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.1.2 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.1.1 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.1.0 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.0.9 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.0.8 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.0.7 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.0.6 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.0.5 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.0.4 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.0.3 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.0.2 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.0.1 app/assets/javascripts/effective_select/overrides.js.coffee
effective_form_inputs-1.0.0 app/assets/javascripts/effective_select/overrides.js.coffee