activeadmin_dynamic_fields 0.4.0 → 0.4.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 +10 -8
- data/app/assets/javascripts/activeadmin/dynamic_fields.js +11 -0
- data/lib/activeadmin/dynamic_fields/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 703a3fcf46aa777dda6ed22421da5a937027a19de733cc461da566d892bf207a
|
4
|
+
data.tar.gz: c5c389c17b60a395a77d0d9d92a0171af83d5f94fb102017c3b01adbf10f7857
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f45524f227c1d73c64eea3f8660aee6e8054617c17f969ed85f3c131048678d8fc0988c24d5421b7a27b6a8787135a0957c8de1d5c7033e13fa92f25a504c6c
|
7
|
+
data.tar.gz: a77b5396c95012b32f2a682c7bb40974f9e60e9f65fc8a0a890595f968a9114ba3c883c3f19f1352b1f84ef8c9ea97a07024887c1209c6e63043a57c5d5cdf19
|
data/README.md
CHANGED
@@ -24,23 +24,25 @@ Options are passed to fields using *input_html* parameter as *data* attributes.
|
|
24
24
|
|
25
25
|
Conditions:
|
26
26
|
- **data-if**: check a condition, values:
|
27
|
-
+ **checked**: check if a checkbox is checked
|
27
|
+
+ **checked**: check if a checkbox is checked (ex. `"data-if": "checked"`)
|
28
28
|
+ **not_checked**: check if a checkbox is not checked
|
29
29
|
+ **blank**: check if a field is blank
|
30
30
|
+ **not_blank**: check if a field is not blank
|
31
31
|
+ **changed**: check if the value of an input is changed (dirty)
|
32
|
-
- **data-eq**: check if a field has a specific value
|
33
|
-
- **data-not**: check if a field
|
34
|
-
- **data-function**: check the return value of a custom function
|
32
|
+
- **data-eq**: check if a field has a specific value (ex. `"data-eq": "42"`)
|
33
|
+
- **data-not**: check if a field has not a specific value
|
34
|
+
- **data-function**: check the return value of a custom function (ex. `"data-function": "my_check"`)
|
35
35
|
|
36
36
|
Actions:
|
37
37
|
- **data-then**: action to trigger (alias **data-action**), values:
|
38
|
-
+ **hide**: hides elements
|
38
|
+
+ **hide**: hides elements (ex. `"data-then": "hide", "data-target": ".errors"`)
|
39
39
|
+ **slide**: hides elements (using sliding)
|
40
40
|
+ **fade**: hides elements (using fading)
|
41
|
-
+ **addClass**: adds classes
|
42
|
-
+ **
|
43
|
-
+ **
|
41
|
+
+ **addClass**: adds classes (ex. `"data-then": "addClass red"`)
|
42
|
+
+ **addStyle**: adds some styles (ex. `"data-then": "addStyle color: #fb1; font-size: 12px"`)
|
43
|
+
+ **setText**: set the text of an element (ex. `"data-then": "setText A sample text"`)
|
44
|
+
+ **setValue**: set the value of an input element (ex. `"data-then": "setValue A sample value"`)
|
45
|
+
+ **callback**: call a function (with arguments: **data-args**) (ex. `"data-then": "callback a_fun"`)
|
44
46
|
- **data-else**: action to trigger when the condition check is not true
|
45
47
|
- **data-args**: arguments passed to the callback function
|
46
48
|
|
@@ -3,6 +3,13 @@
|
|
3
3
|
|
4
4
|
const ACTIONS = {
|
5
5
|
addClass: (el, name) => el.addClass(name),
|
6
|
+
addStyle: (el, extra_style) => {
|
7
|
+
let style = (el.attr('style') || '').trim()
|
8
|
+
if (!style.includes(extra_style)) {
|
9
|
+
if (style) style = style.replace(/;$/, '') + '; ' // ensure style ends with ;
|
10
|
+
el.attr('style', `${style}${extra_style}`)
|
11
|
+
}
|
12
|
+
},
|
6
13
|
callback: (el, name) => {
|
7
14
|
if (window[name]) window[name](el.data('args'))
|
8
15
|
else {
|
@@ -12,6 +19,7 @@
|
|
12
19
|
},
|
13
20
|
fade: el => el.fadeOut(),
|
14
21
|
hide: el => el.hide(),
|
22
|
+
setText: (el, text) => el.text(text),
|
15
23
|
setValue: (el, value) => {
|
16
24
|
if (el.attr('type') == 'checkbox') el.prop('checked', value == '1')
|
17
25
|
else el.val(value)
|
@@ -32,6 +40,9 @@
|
|
32
40
|
|
33
41
|
const REVERSE_ACTIONS = {
|
34
42
|
addClass: (el, name) => el.removeClass(name),
|
43
|
+
addStyle: (el, extra_style) => {
|
44
|
+
if(el.attr('style')) el.attr('style', el.attr('style').replace(extra_style, ''))
|
45
|
+
},
|
35
46
|
fade: el => el.fadeIn(),
|
36
47
|
hide: el => el.show(),
|
37
48
|
slide: el => el.slideDown()
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_dynamic_fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeadmin
|