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
Copy file name to clipboardExpand all lines: README.md
+34-13Lines changed: 34 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,9 @@ The easiest way to show how this plugin works is looking the examples [below](#e
20
20
```
21
21
22
22
## Options
23
-
Options are passed to fields using *input_html* parameter as *data* attributes:
23
+
Options are passed to fields using *input_html* parameter as *data* attributes.
24
+
25
+
Conditions:
24
26
- **data-if**: check a condition, values:
25
27
+ **checked**: check if a checkbox is checked
26
28
+ **not_checked**: check if a checkbox is not checked
@@ -29,17 +31,22 @@ Options are passed to fields using *input_html* parameter as *data* attributes:
29
31
+ **changed**: check if the value of an input is changed (dirty)
30
32
- **data-eq**: check if a field has a specific value
31
33
- **data-not**: check if a field hasn't a specific value
32
-
- **data-target**: target css selector (from parent fieldset, look for the closest match)
33
-
- **data-gtarget**: target css selector globally
34
-
- **data-then**: the action to trigger (alias **data-action**), values:
34
+
- **data-function**: check the return value of a custom function
35
+
36
+
Actions:
37
+
- **data-then**: action to trigger (alias **data-action**), values:
35
38
+ **hide**: hides elements
36
39
+ **slide**: hides elements (using sliding)
37
40
+ **fade**: hides elements (using fading)
38
41
+ **addClass**: adds classes
39
42
+ **setValue**: set a value
40
-
+ **callback**: call a function
41
-
- **data-function**: check the return value of a custom function
42
-
- **data-arg**: argument passed to the custom set function (as array of strings)
43
+
+ **callback**: call a function (with arguments: **data-args**)
44
+
- **data-else**: action to trigger when the condition check is not true
45
+
- **data-args**: arguments passed to the callback function
46
+
47
+
Targets:
48
+
- **data-target**: target css selector (from parent fieldset, look for the closest match)
49
+
- **data-gtarget**: target css selector globally
43
50
44
51
A check condition or a custom check function are required. A trigger action is required too, unless you are using a custom function (in that case it is optional).
45
52
@@ -59,17 +66,25 @@ form do |f|
59
66
end
60
67
```
61
68
62
-
- Add 3 classes (*first*, *second*, *third*) if a checkbox is not checked:
69
+
- Add 3 classes (*first*, *second*, *third*) if a checkbox is not checked, else add "forth" class:
63
70
64
-
`f.input :published, input_html: { data: { if: 'not_checked', then: 'addClass first second third', target: '.grp1' } }`
71
+
```rb
72
+
data = { if: 'not_checked', then: 'addClass first second third', target: '.grp1', else: 'addClass forth' }
73
+
f.input :published, input_html: { data: data }
74
+
```
65
75
66
76
- Set another field value if a string field is blank:
0 commit comments