dependent-fields-rails 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,28 +19,42 @@ toggle = ($parent, showOrHide, method, duration) ->
19
19
  else
20
20
  $parent.hide(duration)
21
21
 
22
- showOrHideDependentFields = (duration = 'fast') ->
22
+
23
+ showOrHideDependentFieldsSelect = (duration = 'fast') ->
23
24
  $select = $(this)
24
25
 
25
- # fields that depend on a select option
26
- $(".js-dependent-fields[data-select-id=#{$select.attr('id')}]").each ->
26
+ showOrHideFields = ->
27
27
  $this = $(this)
28
28
  # use attr here instead of data because we do not want jquery to cast the string into js types
29
29
  showOrHide = _.contains($this.attr('data-option-value').split('|'), $select.val())
30
30
  toggle($this, showOrHide, $this.data('method'), duration)
31
31
 
32
- # fields that depend on a checkbox
33
- $(".js-dependent-fields[data-checkbox-id=#{$select.attr('id')}]").each ->
32
+ $(".js-dependent-fields[data-select-id=#{$select.attr('id')}]").each showOrHideFields
33
+
34
+
35
+ showOrHideDependentFieldsCheckbox = (duration = 'fast') ->
36
+ $checkbox = $(this)
37
+
38
+ showOrHideFields = ->
34
39
  $this = $(this)
35
- showOrHide = $this.data('checkbox-value') == $select.is(':checked')
40
+ showOrHide = $this.data('checkbox-value') == $checkbox.is(':checked')
36
41
  toggle($this, showOrHide, $this.data('method'), duration)
37
42
 
43
+ $(".js-dependent-fields[data-checkbox-id=#{$checkbox.attr('id')}]").each showOrHideFields
44
+
45
+
38
46
  bind = ->
39
- $('select').each _.partial(showOrHideDependentFields, 0)
40
- $('select').change showOrHideDependentFields
47
+ $selects = $('select')
48
+ $selects.not('[data-important]').each _.partial(showOrHideDependentFieldsSelect, 0)
49
+ $selects.filter('[data-important]').each _.partial(showOrHideDependentFieldsSelect, 0)
50
+
51
+ $selects.change showOrHideDependentFieldsSelect
52
+
53
+ $inputs = $('input[type=checkbox]')
54
+ $inputs.not('[data-important]').each _.partial(showOrHideDependentFieldsCheckbox, 0)
55
+ $inputs.filter('[data-important]').each _.partial(showOrHideDependentFieldsCheckbox, 0)
41
56
 
42
- $('input[type=checkbox]').each _.partial(showOrHideDependentFields, 0)
43
- $('input[type=checkbox]').change showOrHideDependentFields
57
+ $inputs.change showOrHideDependentFieldsCheckbox
44
58
 
45
59
 
46
60
  @DependentFields = {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependent-fields-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-20 00:00:00.000000000 Z
12
+ date: 2013-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jquery-rails