Sha256: 9b7aaf45f0644dca018efaacd6c494330688f2468b3e61400d04842ac58ae102

Contents?: true

Size: 1.21 KB

Versions: 231

Compression:

Stored size: 1.21 KB

Contents

$(document).on('change', '.effective-select-or-text input', function(event) {
  $(event.currentTarget).closest('.effective-select-or-text').find('select').val('').trigger('change.select2');
});

$(document).on('change', '.effective-select-or-text select', function(event) {
  $(event.currentTarget).closest('.effective-select-or-text').find('input').val('');
});

// This is the icon that switches them
$(document).on('click', '[data-effective-select-or-text]', function(event) {
  $obj = $(event.currentTarget).closest('.effective-select-or-text');

  $visible = $obj.children('.form-group:visible').first();
  $hidden = $obj.children('.form-group:not(:visible)').first();

  $visible_input = $visible.find('input,textarea,select').first()
  $hidden_input = $hidden.find('input,textarea,select').first()

  required = $visible_input.prop('required') || $hidden_input.prop('required')

  $hidden_input.prop('required', required)
  $visible_input.removeAttr('required')

  $visible.fadeOut('fast', function() {
    $hidden.prop('required', required).detach().insertAfter($visible).fadeIn('fast');
  });

  return false; // This implicitly calls event.preventDefault() to cancel the action, and prevent the link from going somewhere.
});

Version data entries

231 entries across 231 versions & 1 rubygems

Version Path
effective_bootstrap-1.19.2 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.19.1 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.19.0 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.18.7 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.18.4 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.18.3 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.18.2 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.18.1 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.18.0 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.17.6 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.17.5 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.17.4 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.17.3 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.17.2 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.17.1 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.17.0 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.16.4 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.16.3 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.16.2 app/assets/javascripts/effective_select_or_text/initialize.js
effective_bootstrap-1.16.1 app/assets/javascripts/effective_select_or_text/initialize.js