dependent-fields-rails 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +16 -0
- data/vendor/assets/javascripts/dependent-fields.js.coffee +20 -0
- metadata +11 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d2bae5d6eeb6d28e4c494c5f2fa38d92537734bc
|
4
|
+
data.tar.gz: 2c3023eca6b6233669e8fb2817b7c05d2441295c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 67016db054e1d49e1c487d19d9fd332c5d1293e4af96fb4c304155eb10fa16ad949730bb5a75b2e5b484648ceeaf3598e6931744f147d331244e4bc88ed8d35b
|
7
|
+
data.tar.gz: 25e361d990ac61aed66b67b34dbdcf3f3d33b8966b6af0aae553abbf8fe44bc724e6fe34854f96da932da238baee742549bc64345503032343d16da86d2b4f21
|
data/README.md
CHANGED
@@ -56,6 +56,22 @@ Note the data attributes on the js-dependent-fields div.
|
|
56
56
|
The date and filing_nr fields will only be shown if the user checks the priority_enabled field.
|
57
57
|
|
58
58
|
|
59
|
+
### Depending on a radio input element
|
60
|
+
|
61
|
+
Relevant radio inputs are selected by name and not by id, because radio inputs in the same group have different ids but the same name.
|
62
|
+
Note the data attributes on the js-dependent-fields div.
|
63
|
+
|
64
|
+
= simple_form_for(@filing) do
|
65
|
+
= f.input :registration_office, collection: ['habm', 'dpma'], as: :radio_buttons
|
66
|
+
|
67
|
+
.js-dependent-fields[data-radio-name='filing[registration_office]' data-radio-value='habm']
|
68
|
+
= f.input :language, collection: ['english', 'german']
|
69
|
+
|
70
|
+
The language selector will only be shown if the user selects 'habm' in the registration office.
|
71
|
+
|
72
|
+
You can also specify multiple option values by seperating them with `|`. For example: `data-option-value='habm|dpma'`
|
73
|
+
|
74
|
+
|
59
75
|
### Disabling instead of hiding fields
|
60
76
|
|
61
77
|
Add `data-method='disable'` to the js-dependent-fields div.
|
@@ -43,6 +43,20 @@ showOrHideDependentFieldsCheckbox = (duration = 'fast') ->
|
|
43
43
|
$(".js-dependent-fields[data-checkbox-id=#{$checkbox.attr('id')}]").each showOrHideFields
|
44
44
|
|
45
45
|
|
46
|
+
showOrHideDependentFieldsRadio = (duration = 'fast') ->
|
47
|
+
$radio = $(this)
|
48
|
+
|
49
|
+
showOrHideFields = ->
|
50
|
+
$this = $(this)
|
51
|
+
# use checked radio input of this radio input group
|
52
|
+
$checkedRadio = $("input:checked[name=#{$radio.attr('name').replace('[', '\\[').replace(']', '\\]')}]")
|
53
|
+
# use attr here instead of data because we do not want jquery to cast the string into js types
|
54
|
+
showOrHide = _.contains($this.attr('data-radio-value').split('|'), $checkedRadio.val())
|
55
|
+
toggle($this, showOrHide, $this.data('method'), duration)
|
56
|
+
|
57
|
+
$(".js-dependent-fields[data-radio-name=#{$radio.attr('name').replace('[', '\\[').replace(']', '\\]')}]").each showOrHideFields
|
58
|
+
|
59
|
+
|
46
60
|
bind = ->
|
47
61
|
$selects = $('select')
|
48
62
|
$selects.not('[data-important]').each _.partial(showOrHideDependentFieldsSelect, 0)
|
@@ -56,6 +70,12 @@ bind = ->
|
|
56
70
|
|
57
71
|
$inputs.change showOrHideDependentFieldsCheckbox
|
58
72
|
|
73
|
+
$radios = $('input[type=radio]')
|
74
|
+
$radios.not('[data-important]').each _.partial(showOrHideDependentFieldsRadio, 0)
|
75
|
+
$radios.filter('[data-important]').each _.partial(showOrHideDependentFieldsRadio, 0)
|
76
|
+
|
77
|
+
$radios.change showOrHideDependentFieldsRadio
|
78
|
+
|
59
79
|
|
60
80
|
@DependentFields = {
|
61
81
|
bind
|
metadata
CHANGED
@@ -1,52 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dependent-fields-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Lion Vollnhals
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-06-12 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: jquery-rails
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: coffee-rails
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: railties
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -71,27 +64,26 @@ files:
|
|
71
64
|
- MIT-LICENSE
|
72
65
|
homepage: https://github.com/vollnhals/dependent-fields-rails
|
73
66
|
licenses: []
|
67
|
+
metadata: {}
|
74
68
|
post_install_message:
|
75
69
|
rdoc_options: []
|
76
70
|
require_paths:
|
77
71
|
- lib
|
78
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
73
|
requirements:
|
81
|
-
- -
|
74
|
+
- - '>='
|
82
75
|
- !ruby/object:Gem::Version
|
83
76
|
version: '0'
|
84
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
78
|
requirements:
|
87
|
-
- -
|
79
|
+
- - '>='
|
88
80
|
- !ruby/object:Gem::Version
|
89
81
|
version: '0'
|
90
82
|
requirements: []
|
91
83
|
rubyforge_project:
|
92
|
-
rubygems_version:
|
84
|
+
rubygems_version: 2.0.3
|
93
85
|
signing_key:
|
94
|
-
specification_version:
|
86
|
+
specification_version: 4
|
95
87
|
summary: DependentFields makes it easy to hide or show dependent fields in forms based
|
96
88
|
on select or checkbox values
|
97
89
|
test_files: []
|