Skip to content

Commit

Permalink
fix do not disable/enable select2 if it was not used on this field
Browse files Browse the repository at this point in the history
  • Loading branch information
Toxix committed Jan 6, 2016
1 parent 1532dfa commit c6a394f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions vendor/assets/javascripts/dependent-fields.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ toggle = ($parent, showOrHide, method, duration) ->
$fieldsAndBtns.filter('[data-dependent-fields-disabled=no]').removeAttr('disabled')
if $.fn.select2
$select2 = $parentVisible.find('.select2')
$select2.filter('[data-dependent-fields-disabled=no]').select2('enable')
$select2disabled = $select2.filter('[data-dependent-fields-disabled=no]')
$select2disabled.select2('enable') if $select2disabled.length > 0
$select2.removeAttr('data-dependent-fields-disabled')
$fieldsAndBtns.removeAttr('data-dependent-fields-disabled')
if method != 'disable' # hide or default
Expand All @@ -32,7 +33,9 @@ toggle = ($parent, showOrHide, method, duration) ->
# disable things
# use attr instead of prop, because prop does not work with twitter bootstrap button
$parent.find(fieldsAndBtnsSelector).attr('disabled', 'disabled')
$parent.find('.select2').select2('disable') if $.fn.select2
if $.fn.select2
$select2enabled = $parent.find('.select2')
$select2enabled.select2('disable') if $select2enabled.length > 0
if method != 'disable' # hide or default
$parent.find(fieldsSelector).filter('[required]').removeAttr('required').attr('data-dependent-fields-required', 'required')
$parent.hide(duration)
Expand Down

0 comments on commit c6a394f

Please sign in to comment.