You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An Active Admin plugin to add dynamic behaviors to some fields.
4
4
5
5
Features:
6
+
6
7
- set conditional checks on fields
7
8
- trigger actions on target elements
8
9
- inline field editing
@@ -11,6 +12,7 @@ Features:
11
12
The easiest way to show how this plugin works is looking the examples [below](#examples).
12
13
13
14
## Install
15
+
14
16
- Add to your Gemfile: `gem 'activeadmin_dynamic_fields'`
15
17
- Execute bundle
16
18
- Add at the end of your ActiveAdmin javascripts (_app/assets/javascripts/active_admin.js_):
@@ -20,9 +22,11 @@ The easiest way to show how this plugin works is looking the examples [below](#e
20
22
```
21
23
22
24
## Options
25
+
23
26
Options are passed to fields using *input_html* parameter as *data* attributes.
24
27
25
28
Conditions:
29
+
26
30
-**data-if**: check a condition, values:
27
31
+**checked**: check if a checkbox is checked (ex. `"data-if": "checked"`)
28
32
+**not_checked**: check if a checkbox is not checked
@@ -36,6 +40,7 @@ Conditions:
36
40
-**data-function**: check the return value of a custom function (ex. `"data-function": "my_check"`)
37
41
38
42
Actions:
43
+
39
44
-**data-then**: action to trigger (alias **data-action**), values:
40
45
+**hide**: hides elements (ex. `"data-then": "hide", "data-target": ".errors"`)
41
46
+**slide**: hides elements (using sliding)
@@ -49,6 +54,7 @@ Actions:
49
54
-**data-args**: arguments passed to the callback function
50
55
51
56
Targets:
57
+
52
58
-**data-target**: target css selector (from parent fieldset, look for the closest match)
53
59
-**data-gtarget**: target css selector globally
54
60
@@ -57,6 +63,7 @@ A check condition or a custom check function are required. A trigger action is r
57
63
## Examples
58
64
59
65
### Dynamic fields examples
66
+
60
67
- A checkbox that hides other fields if is checked (ex. model *Article*):
61
68
62
69
```rb
@@ -128,6 +135,7 @@ function on_change_category(el) {
128
135
```
129
136
130
137
### Inline editing examples
138
+
131
139
- Prepare a custom member action to save data, an *update* helper function is available (third parameter is optional, allow to filter using strong parameters):
132
140
133
141
```rb
@@ -165,6 +173,7 @@ end
165
173
```
166
174
167
175
### Dialog example
176
+
168
177
Example with 2 models: *Author* and *Article*
169
178
170
179
Prepare the content dialog - in Active Admin Author config:
@@ -208,13 +217,16 @@ end
208
217
The link url is loaded via AJAX before opening the dialog.
209
218
210
219
## Do you like it? Star it!
220
+
211
221
If you use this component just star it. A developer is more motivated to improve a project when there is some interest. My other [Active Admin components](https://github.com/blocknotes?utf8=✓&tab=repositories&q=activeadmin&type=source).
212
222
213
223
Or consider offering me a coffee, it's a small thing but it is greatly appreciated: [about me](https://www.blocknot.es/about-me).
0 commit comments