activeadmin_dynamic_fields 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42ac2b763d8f98e2e55cf81e3ec76aecf16cec7e
|
4
|
+
data.tar.gz: 9a7c58695fbb59281f948ce192bfeb0aefe79e2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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-
|
41
|
-
- **data-
|
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
|
61
|
+
- Set another field value if a string field is blank:
|
64
62
|
|
65
|
-
`f.input :title, input_html: {
|
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: {
|
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 =
|
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 =
|
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 ) {
|