activeadmin_dynamic_fields 0.6.4 → 0.8.0

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
  SHA256:
3
- metadata.gz: 1a0aa1741561ea938be8cfdfb7d75df0b85ba24dcdf303639ac3824ffc6ddd4f
4
- data.tar.gz: 208287487042b2ef3de93b20f9a733383e470e44473c40b398b3600ec18f11bc
3
+ metadata.gz: 3ec3982ce825b53d7710740218eb71b4d0fe940efd6a0f0bf05fc58d2b736e4a
4
+ data.tar.gz: d58f6ef07c54556a525fc05c14db397fe09f0740dfa4854e176b9e4f6d6d7121
5
5
  SHA512:
6
- metadata.gz: 6817a8dccfb3691bf61cfe2f8a30d0dd51fb45b40becc20fab9b36fe9b8c573e9f78f68dc12e6c8a0e91c34d2416d773f5f3a1d62359b32e2888e68b2d19113a
7
- data.tar.gz: 0f15dcb8b29b7cbf73ba0e6932b6a0dd42a91ca883357ea0024da13b5b65867c2cf22bcae0458967ec37f70a7667607c0cb65be8aa43b17319b83595c2ee8cbd
6
+ metadata.gz: cbeb94a81ae9c1fce990f132e50afd821c96ce673ab5fab5b1d9e69d45b83d43d468806bd804ca2696f81d27516e5831a89eb226e905a7c2f3cc441833de42f9
7
+ data.tar.gz: 1d7324b9393e47f9194ee3c86a4cea7c4b0511f19d2823c39fe554275c342ced4ed9cc9dac897ca0aee3eb3dd17ecc53c4f67bcc216addf4220b02f2e4ac6445
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 => el.val().trim(),
43
- not_checked: el => !el.is(':checked')
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 data_if = this.el.data('if')
95
- let value = data_if ? CONDITIONS[data_if.trim()] : null
96
- if (value) return { condition: value }
97
-
98
- value = this.el.data('eq')
99
- if (value) return { condition: CONDITIONS['eq'], condition_arg: value }
100
-
101
- value = this.el.data('not')
102
- if (value) return { condition: CONDITIONS['not'], condition_arg: value }
103
-
104
- value = this.el.data('match')
105
- if (value) return { condition: CONDITIONS['match'], condition_arg: new RegExp(value) }
106
-
107
- value = this.el.data('mismatch')
108
- if (value) return { condition: CONDITIONS['mismatch'], condition_arg: new RegExp(value) }
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) {
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveAdmin
4
4
  module DynamicFields
5
- VERSION = '0.6.4'
5
+ VERSION = '0.8.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_dynamic_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.8.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-09 00:00:00.000000000 Z
11
+ date: 2023-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '2.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: appraisal
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -74,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
80
  - !ruby/object:Gem::Version
75
81
  version: '0'
76
82
  requirements: []
77
- rubygems_version: 3.1.6
83
+ rubygems_version: 3.4.19
78
84
  signing_key:
79
85
  specification_version: 4
80
86
  summary: Dynamic fields for ActiveAdmin