activeadmin_dynamic_fields 0.1.4 → 0.1.5

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: 1ed3a311fa689cf4f9457fd700a694f157a9abe3
4
- data.tar.gz: 6313408d435051e63fc80993f8bf8129da485055
3
+ metadata.gz: 42ac2b763d8f98e2e55cf81e3ec76aecf16cec7e
4
+ data.tar.gz: 9a7c58695fbb59281f948ce192bfeb0aefe79e2e
5
5
  SHA512:
6
- metadata.gz: 816e1d338c5bc05cc86071a57222cfb5a9615809ed79acb1a972bcf2e7e0c1f30f58b4eac44690e47ac63de1829af2e6bbfb899ae218defea703612df88b9083
7
- data.tar.gz: bb91d68394ab4913c4c1346193e88e9fd2fcf2dd8dffafda0bb1126940015e68ccb9fcbdaedbdff90245d9b6a89f191e2f2ef954ac98a6a5dd4bed9764d0a767
6
+ metadata.gz: 613eeec1ba5f472a7309a0b1463bd06ced96044def8845005f6fc3fad7c44cc40efbbece500af140251ab03ad6001b21f1d40b3205b4bb70167ca819156dfbc0
7
+ data.tar.gz: f60670bc64107e1c7d57f19f9792c5dd2485d5d910f22ec970c5f572d7d2703e18c626457bbefc1ab03ff530d1c4549d42e3d2230ee89df92ef520a09c106671
data/README.md CHANGED
@@ -28,7 +28,6 @@ Options are passed to fields using *input_html* parameter as *data* attributes:
28
28
  + **not_blank**: check if a field is not blank
29
29
  - **data-eq**: check if a field has a specific value
30
30
  - **data-not**: check if a field hasn't a specific value
31
- - **data-function**: check the return value of a custom function
32
31
  - **data-target**: target css selector
33
32
  - **data-action**: the action to trigger, values:
34
33
  + **hide**: hides elements
@@ -37,9 +36,8 @@ Options are passed to fields using *input_html* parameter as *data* attributes:
37
36
  + **addClass**: adds classes
38
37
  + **setValue**: set a value
39
38
  + **callback**: call a function
40
- - **data-value**: value to set
41
- - **data-callback**: custom function for setting a value
42
- - **data-arg**: argument passed to the custom set function
39
+ - **data-function**: check the return value of a custom function
40
+ - **data-arg**: argument passed to the custom set function (as array of strings)
43
41
 
44
42
  ## Examples of dynamic fields
45
43
 
@@ -60,11 +58,11 @@ end
60
58
 
61
59
  `f.input :published, input_html: { data: { if: 'checked', action: 'addClass first second third', target: '.grp1' } }`
62
60
 
63
- - Set another field value if a string field is blank (with alternative syntax for data attributes):
61
+ - Set another field value if a string field is blank:
64
62
 
65
- `f.input :title, input_html: { 'data-if': 'blank', 'data-action': 'setValue', 'data-target': '#article_position', 'data-value': '10' }`
63
+ `f.input :title, input_html: { data: { if: 'blank', action: 'setValue 10', target: '#article_position' } }`
66
64
 
67
- - Use a custom function for conditional check (*title_not_empty()* must be available on global scope):
65
+ - Use a custom function for conditional check (*title_not_empty()* must be available on global scope) (with alternative syntax for data attributes):
68
66
 
69
67
  `f.input :title, input_html: { 'data-function': 'title_empty', 'data-action': 'slide', 'data-target': '#article_description_input' }`
70
68
 
@@ -76,7 +74,7 @@ function title_empty( el ) {
76
74
 
77
75
  - Call a callback function as action:
78
76
 
79
- `f.input :published, input_html: { 'data-if': 'checked', 'data-action': 'callback', 'data-callback': 'set_title', 'data-args': '["[unpublished]"]' }`
77
+ `f.input :published, input_html: { data: { if: 'checked', action: 'callback set_title', args: '["Unpublished !"]' } }`
80
78
 
81
79
  ```js
82
80
  function set_title( args ) {
@@ -58,15 +58,15 @@ function dfSetupField( el ) {
58
58
  else target.fadeOut();
59
59
  });
60
60
  }
61
- else if( action == 'setValue' ) {
62
- var val = el.data( 'value' ) ? el.data( 'value' ) : '';
61
+ else if( action.substr( 0, 8 ) == 'setValue' ) {
62
+ var val = action.substr( 8 ).trim();
63
63
  if( dfEvalCondition( el, args ) ) dfSetValue( target, val );
64
64
  el.on( 'change', function( event ) {
65
65
  if( dfEvalCondition( $(this), args ) ) dfSetValue( target, val );
66
66
  });
67
67
  }
68
- else if( action == 'callback' ) {
69
- var cb = el.data( 'callback' );
68
+ else if( action.substr( 0, 8 ) == 'callback' ) {
69
+ var cb = action.substr( 8 ).trim();
70
70
  if( cb && window[cb] ) {
71
71
  if( dfEvalCondition( el, args ) ) window[cb]( el.data( 'args' ) );
72
72
  el.on( 'change', function( event ) {
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
2
  module DynamicFields
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.5'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_dynamic_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattia Roccoberton