activeadmin_dynamic_fields 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35c4dfd1640b8577278714cdbd2b4680e01f79e2
4
- data.tar.gz: 6c157e9f6d829dadba72fa2ad4dcd8c85d62199c
3
+ metadata.gz: 1ed3a311fa689cf4f9457fd700a694f157a9abe3
4
+ data.tar.gz: 6313408d435051e63fc80993f8bf8129da485055
5
5
  SHA512:
6
- metadata.gz: 1ee9565520e9e58036782be7e297d438c90bba3adb96877caa49f4ca64224041a480d9d29b85d5fec80a7822e654925059b719705bd0a120ef59f59322a57c9e
7
- data.tar.gz: f4122e8d584dc2a42d4fd1eec7b2ec68be46171aa33113759b40cdad3ef9d6de4bd6cb77f4cdf75424afdbb2f66d4bb67475c47e3c22307d040c23e81d129a75
6
+ metadata.gz: 816e1d338c5bc05cc86071a57222cfb5a9615809ed79acb1a972bcf2e7e0c1f30f58b4eac44690e47ac63de1829af2e6bbfb899ae218defea703612df88b9083
7
+ data.tar.gz: bb91d68394ab4913c4c1346193e88e9fd2fcf2dd8dffafda0bb1126940015e68ccb9fcbdaedbdff90245d9b6a89f191e2f2ef954ac98a6a5dd4bed9764d0a767
data/README.md CHANGED
@@ -6,9 +6,9 @@ Features:
6
6
 
7
7
  - set conditional checks on fields
8
8
  - trigger some actions on other fields
9
- - create links to load some content in a dialogs
9
+ - create links to load some content in a dialog
10
10
 
11
- The easiest way to show how this plugin works is looking the examples (below).
11
+ The easiest way to show how this plugin works is looking the examples [below](#examples-of-dynamic-fields).
12
12
 
13
13
  ## Install
14
14
 
@@ -19,7 +19,7 @@ The easiest way to show how this plugin works is looking the examples (below).
19
19
 
20
20
  ## Options
21
21
 
22
- Options are passed to fields using *input_html* parameter:
22
+ Options are passed to fields using *input_html* parameter as *data* attributes:
23
23
 
24
24
  - **data-if**: check a condition, values:
25
25
  + **checked**: check if a checkbox is checked
@@ -34,6 +34,7 @@ Options are passed to fields using *input_html* parameter:
34
34
  + **hide**: hides elements
35
35
  + **slide**: hides elements (using sliding)
36
36
  + **fade**: hides elements (using fading)
37
+ + **addClass**: adds classes
37
38
  + **setValue**: set a value
38
39
  + **callback**: call a function
39
40
  - **data-value**: value to set
@@ -47,7 +48,7 @@ Options are passed to fields using *input_html* parameter:
47
48
  ```rb
48
49
  form do |f|
49
50
  f.inputs 'Article' do
50
- f.input :published, input_html: { 'data-if': 'not_checked', 'data-action': 'hide', 'data-target': '.grp1' }
51
+ f.input :published, input_html: { data: { if: 'not_checked', action: 'hide', target: '.grp1' } }
51
52
  f.input :online_date, wrapper_html: { class: 'grp1' }
52
53
  f.input :position, wrapper_html: { class: 'grp1' }
53
54
  end
@@ -55,7 +56,11 @@ form do |f|
55
56
  end
56
57
  ```
57
58
 
58
- - Set another field value if a string field is blank:
59
+ - Add 3 classes (*first*, *second*, *third*) if a checkbox is true:
60
+
61
+ `f.input :published, input_html: { data: { if: 'checked', action: 'addClass first second third', target: '.grp1' } }`
62
+
63
+ - Set another field value if a string field is blank (with alternative syntax for data attributes):
59
64
 
60
65
  `f.input :title, input_html: { 'data-if': 'blank', 'data-action': 'setValue', 'data-target': '#article_position', 'data-value': '10' }`
61
66
 
@@ -75,6 +75,15 @@ function dfSetupField( el ) {
75
75
  }
76
76
  else console.log( 'Warning - activeadmin_dynamic_fields: ' + cb + '() not available [2]' );
77
77
  }
78
+ else if( action.substr( 0, 8 ) == 'addClass' ) {
79
+ var classes = action.substr( 8 ).trim();
80
+ if( dfEvalCondition( el, args ) ) target.removeClass( classes );
81
+ else target.addClass( classes );
82
+ el.on( 'change', function( event ) {
83
+ if( dfEvalCondition( $(this), args ) ) target.removeClass( classes );
84
+ else target.addClass( classes );
85
+ });
86
+ }
78
87
  else if( args.fn ) { // function without action
79
88
  dfEvalCondition( el, args );
80
89
  el.on( 'change', function( event ) {
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
2
  module DynamicFields
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.4'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_dynamic_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattia Roccoberton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-10 00:00:00.000000000 Z
11
+ date: 2017-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin