activeadmin_dynamic_fields 0.6.4 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/app/assets/javascripts/activeadmin/dynamic_fields.js +27 -17
- 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: c205fcaf09eb8f64858be70e3edad674abbf894ee2f65c2c236258bb8f43af86
|
4
|
+
data.tar.gz: 488ce2f3f4ed09165839398014614b198e23d830df8c2fcbb63b4dd1547eba0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 371d705fc20dc6e2062b54bd81a480979c70e8473727579da8282a06581f7826c80a50f71a3202e695f01b5cd272e3d3e564f626304db35d8ad4e9aa19af8a45
|
7
|
+
data.tar.gz: 48d1c6a52aa51b417eb1f55cc61fad9287d263c922b224f08b40492517edf9b0af35af5b49089eaa330f347d1466cf5d90700d77bfb482369942c29705a3af33
|
data/README.md
CHANGED
@@ -47,12 +47,12 @@ Conditions:
|
|
47
47
|
|
48
48
|
- **data-if**: check a condition, values:
|
49
49
|
+ **checked**: check if a checkbox is checked (ex. `"data-if": "checked"`)
|
50
|
-
+ **not_checked**: check if a checkbox is not checked
|
50
|
+
+ **not_checked**: check if a checkbox is not checked (equivalent to `"data-if": "!checked"`)
|
51
51
|
+ **blank**: check if a field is blank
|
52
52
|
+ **not_blank**: check if a field is not blank
|
53
53
|
+ **changed**: check if the value of an input is changed (dirty)
|
54
|
-
- **data-eq**: check if a field has a specific value (ex. `"data-eq": "42"`)
|
55
|
-
- **data-not**: check if a field has not a specific value
|
54
|
+
- **data-eq**: check if a field has a specific value (ex. `"data-eq": "42"` or `"data-eq": "!5"`)
|
55
|
+
- **data-not**: check if a field has not a specific value (equivalent to `"data-eq": "!something"`)
|
56
56
|
- **data-match**: check if a field match a regexp
|
57
57
|
- **data-mismatch**: check if a field doesn't match a regexp (ex. `"data-mismatch": "^\d+$"`)
|
58
58
|
- **data-function**: check the return value of a custom function (ex. `"data-function": "my_check"`)
|
@@ -39,8 +39,8 @@
|
|
39
39
|
match: (el, regexp) => regexp.test(el.val()),
|
40
40
|
mismatch: (el, regexp) => !regexp.test(el.val()),
|
41
41
|
not: (el, value) => el.val() != value,
|
42
|
-
not_blank: el =>
|
43
|
-
not_checked: el => !
|
42
|
+
not_blank: el => !CONDITIONS.blank(el),
|
43
|
+
not_checked: el => !CONDITIONS.checked(el)
|
44
44
|
}
|
45
45
|
|
46
46
|
const REVERSE_ACTIONS = {
|
@@ -53,6 +53,8 @@
|
|
53
53
|
slide: el => el.slideDown()
|
54
54
|
}
|
55
55
|
|
56
|
+
const REGEXP_NOT = /^!\s*/
|
57
|
+
|
56
58
|
class Field {
|
57
59
|
constructor(el) {
|
58
60
|
this.el = el
|
@@ -91,21 +93,29 @@
|
|
91
93
|
}
|
92
94
|
|
93
95
|
evaluateCondition() {
|
94
|
-
let
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
if (value
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
if (value
|
106
|
-
|
107
|
-
|
108
|
-
|
96
|
+
let value
|
97
|
+
if (value = this.el.data('if')) {
|
98
|
+
if (REGEXP_NOT.test(value)) value = 'not_' + value.replace(REGEXP_NOT, '')
|
99
|
+
return { condition: CONDITIONS[value] }
|
100
|
+
}
|
101
|
+
if (value = this.el.data('eq')) {
|
102
|
+
if (REGEXP_NOT.test(value)) {
|
103
|
+
return { condition: CONDITIONS['not'], condition_arg: value.replace(REGEXP_NOT, '') }
|
104
|
+
}
|
105
|
+
return { condition: CONDITIONS['eq'], condition_arg: value }
|
106
|
+
}
|
107
|
+
if (value = this.el.data('not')) {
|
108
|
+
if (REGEXP_NOT.test(value)) {
|
109
|
+
return { condition: CONDITIONS['eq'], condition_arg: value.replace(REGEXP_NOT, '') }
|
110
|
+
}
|
111
|
+
return { condition: CONDITIONS['not'], condition_arg: value }
|
112
|
+
}
|
113
|
+
if (value = this.el.data('match')) {
|
114
|
+
return { condition: CONDITIONS['match'], condition_arg: new RegExp(value) }
|
115
|
+
}
|
116
|
+
if (value = this.el.data('mismatch')) {
|
117
|
+
return { condition: CONDITIONS['mismatch'], condition_arg: new RegExp(value) }
|
118
|
+
}
|
109
119
|
|
110
120
|
this.custom_function = this.el.data('function')
|
111
121
|
if (this.custom_function) {
|
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
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeadmin
|