dependent-fields-rails 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -19,28 +19,42 @@ toggle = ($parent, showOrHide, method, duration) ->
|
|
19
19
|
else
|
20
20
|
$parent.hide(duration)
|
21
21
|
|
22
|
-
|
22
|
+
|
23
|
+
showOrHideDependentFieldsSelect = (duration = 'fast') ->
|
23
24
|
$select = $(this)
|
24
25
|
|
25
|
-
|
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
|
-
|
33
|
-
|
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') == $
|
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')
|
40
|
-
$('
|
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
|
-
$
|
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.
|
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-
|
12
|
+
date: 2013-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jquery-rails
|