activeadmin_dynamic_fields 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/app/assets/javascripts/activeadmin/dynamic_fields.js +18 -15
- data/lib/activeadmin/dynamic_fields/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a41854a61414d8eb8f8c35556fd0cbfdfa8364ed
|
4
|
+
data.tar.gz: 85340ca45697226edb75f74a5189c812400e19cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72f93305d28ba3134437e19d062cc03a654113776d8aecfceb78f06d0939caeb8a3e01e4bca0f273db11be3b4358d2a7d72a57fbd838248c4af6108c54a44d42
|
7
|
+
data.tar.gz: 45231b55baf2d328e05e83d843285858487067f7798859c8b0d5fbfee11663e282c9230a41a8a5efed1a71082f68e1892c31e06fbc09893f9d12f69f6986ddec
|
data/README.md
CHANGED
@@ -27,6 +27,7 @@ Options are passed to fields using *input_html* parameter as *data* attributes:
|
|
27
27
|
+ **not_checked**: check if a checkbox is not checked
|
28
28
|
+ **blank**: check if a field is blank
|
29
29
|
+ **not_blank**: check if a field is not blank
|
30
|
+
+ **changed**: check if the value of an input is changed (dirty)
|
30
31
|
- **data-eq**: check if a field has a specific value
|
31
32
|
- **data-not**: check if a field hasn't a specific value
|
32
33
|
- **data-target**: target css selector (from parent fieldset, look for the closest match)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
// Evaluate a condition
|
2
|
-
function dfEvalCondition( el, args ) {
|
2
|
+
function dfEvalCondition( el, args, on_change ) {
|
3
3
|
if( args.fn ) {
|
4
4
|
if( args.fn && window[args.fn] ) return !window[args.fn]( el );
|
5
5
|
else console.log( 'Warning - activeadmin_dynamic_fields: ' + args.fn + '() not available [1]' );
|
@@ -16,6 +16,9 @@ function dfEvalCondition( el, args ) {
|
|
16
16
|
else if( args.if == 'not_blank' ) {
|
17
17
|
return el.val().length !== 0 && el.val().trim();
|
18
18
|
}
|
19
|
+
else if( args.if == 'changed' ) {
|
20
|
+
return on_change;
|
21
|
+
}
|
19
22
|
else if( args.eq ) {
|
20
23
|
return el.val() == args.eq;
|
21
24
|
}
|
@@ -36,59 +39,59 @@ function dfSetupField( el ) {
|
|
36
39
|
if( el.data( 'target' ) ) target = el.closest( 'fieldset' ).find( el.data( 'target' ) ); // closest find for has many associations
|
37
40
|
else if( el.data( 'gtarget' ) ) target = $( el.data( 'gtarget' ) );
|
38
41
|
if( action == 'hide' ) {
|
39
|
-
if( dfEvalCondition( el, args ) ) target.hide();
|
42
|
+
if( dfEvalCondition( el, args, false ) ) target.hide();
|
40
43
|
else target.show();
|
41
44
|
el.on( 'change', function( event ) {
|
42
|
-
if( dfEvalCondition( $(this), args ) ) target.hide();
|
45
|
+
if( dfEvalCondition( $(this), args, true ) ) target.hide();
|
43
46
|
else target.show();
|
44
47
|
});
|
45
48
|
}
|
46
49
|
else if( action == 'slide' ) {
|
47
|
-
if( dfEvalCondition( el, args ) ) target.slideDown();
|
50
|
+
if( dfEvalCondition( el, args, false ) ) target.slideDown();
|
48
51
|
else target.slideUp();
|
49
52
|
el.on( 'change', function( event ) {
|
50
|
-
if( dfEvalCondition( $(this), args ) ) target.slideDown();
|
53
|
+
if( dfEvalCondition( $(this), args, true ) ) target.slideDown();
|
51
54
|
else target.slideUp();
|
52
55
|
});
|
53
56
|
}
|
54
57
|
else if( action == 'fade' ) {
|
55
|
-
if( dfEvalCondition( el, args ) ) target.fadeIn();
|
58
|
+
if( dfEvalCondition( el, args, false ) ) target.fadeIn();
|
56
59
|
else target.fadeOut();
|
57
60
|
el.on( 'change', function( event ) {
|
58
|
-
if( dfEvalCondition( $(this), args ) ) target.fadeIn();
|
61
|
+
if( dfEvalCondition( $(this), args, true ) ) target.fadeIn();
|
59
62
|
else target.fadeOut();
|
60
63
|
});
|
61
64
|
}
|
62
65
|
else if( action.substr( 0, 8 ) == 'setValue' ) {
|
63
66
|
var val = action.substr( 8 ).trim();
|
64
|
-
if( dfEvalCondition( el, args ) ) dfSetValue( target, val );
|
67
|
+
if( dfEvalCondition( el, args, false ) ) dfSetValue( target, val );
|
65
68
|
el.on( 'change', function( event ) {
|
66
|
-
if( dfEvalCondition( $(this), args ) ) dfSetValue( target, val );
|
69
|
+
if( dfEvalCondition( $(this), args, true ) ) dfSetValue( target, val );
|
67
70
|
});
|
68
71
|
}
|
69
72
|
else if( action.substr( 0, 8 ) == 'callback' ) {
|
70
73
|
var cb = action.substr( 8 ).trim();
|
71
74
|
if( cb && window[cb] ) {
|
72
|
-
if( dfEvalCondition( el, args ) ) window[cb]( el.data( 'args' ) );
|
75
|
+
if( dfEvalCondition( el, args, false ) ) window[cb]( el.data( 'args' ) );
|
73
76
|
el.on( 'change', function( event ) {
|
74
|
-
if( dfEvalCondition( $(this), args ) ) window[cb]( el.data( 'args' ) );
|
77
|
+
if( dfEvalCondition( $(this), args, true ) ) window[cb]( el.data( 'args' ) );
|
75
78
|
});
|
76
79
|
}
|
77
80
|
else console.log( 'Warning - activeadmin_dynamic_fields: ' + cb + '() not available [2]' );
|
78
81
|
}
|
79
82
|
else if( action.substr( 0, 8 ) == 'addClass' ) {
|
80
83
|
var classes = action.substr( 8 ).trim();
|
81
|
-
if( dfEvalCondition( el, args ) ) target.removeClass( classes );
|
84
|
+
if( dfEvalCondition( el, args, false ) ) target.removeClass( classes );
|
82
85
|
else target.addClass( classes );
|
83
86
|
el.on( 'change', function( event ) {
|
84
|
-
if( dfEvalCondition( $(this), args ) ) target.removeClass( classes );
|
87
|
+
if( dfEvalCondition( $(this), args, true ) ) target.removeClass( classes );
|
85
88
|
else target.addClass( classes );
|
86
89
|
});
|
87
90
|
}
|
88
91
|
else if( args.fn ) { // function without action
|
89
|
-
dfEvalCondition( el, args );
|
92
|
+
dfEvalCondition( el, args, false );
|
90
93
|
el.on( 'change', function( event ) {
|
91
|
-
dfEvalCondition( el, args );
|
94
|
+
dfEvalCondition( el, args, true );
|
92
95
|
});
|
93
96
|
}
|
94
97
|
}
|