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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a0aa1741561ea938be8cfdfb7d75df0b85ba24dcdf303639ac3824ffc6ddd4f
4
- data.tar.gz: 208287487042b2ef3de93b20f9a733383e470e44473c40b398b3600ec18f11bc
3
+ metadata.gz: c205fcaf09eb8f64858be70e3edad674abbf894ee2f65c2c236258bb8f43af86
4
+ data.tar.gz: 488ce2f3f4ed09165839398014614b198e23d830df8c2fcbb63b4dd1547eba0d
5
5
  SHA512:
6
- metadata.gz: 6817a8dccfb3691bf61cfe2f8a30d0dd51fb45b40becc20fab9b36fe9b8c573e9f78f68dc12e6c8a0e91c34d2416d773f5f3a1d62359b32e2888e68b2d19113a
7
- data.tar.gz: 0f15dcb8b29b7cbf73ba0e6932b6a0dd42a91ca883357ea0024da13b5b65867c2cf22bcae0458967ec37f70a7667607c0cb65be8aa43b17319b83595c2ee8cbd
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 => 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.7.0'
6
6
  end
7
7
  end
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.6.4
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-09 00:00:00.000000000 Z
11
+ date: 2022-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin