activeadmin_dynamic_fields 0.4.0 → 0.4.2

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: bf72bdd2f498f04dd656b044b1b711cd1e4962ad98d9190807ac9b4bfa423ba0
4
- data.tar.gz: 036c3c43e6b00ed99b900f21216b824b00dccbf3a3d871cdfa331080f30eceb3
3
+ metadata.gz: 703a3fcf46aa777dda6ed22421da5a937027a19de733cc461da566d892bf207a
4
+ data.tar.gz: c5c389c17b60a395a77d0d9d92a0171af83d5f94fb102017c3b01adbf10f7857
5
5
  SHA512:
6
- metadata.gz: 94007fc44295a8e251f011ef78884c31a03904e53d264bc9b5aa716645c268a0c3a7343f75b0831f790a36b14f1dcdb03ea6a87fb8e819accb36b871c5617f14
7
- data.tar.gz: bc6beec26ce12eb2f40c70cc8b9fd12f3cdd416ecf735380fd77343d395e7e7b3f2665cfc2fed8a8339651dcbc12db1eaaae3ce7c6019b5cf6bdf133c4390e31
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 hasn't a specific value
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
- + **setValue**: set a value
43
- + **callback**: call a function (with arguments: **data-args**)
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()
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveAdmin
4
4
  module DynamicFields
5
- VERSION = '0.4.0'
5
+ VERSION = '0.4.2'
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.4.0
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-22 00:00:00.000000000 Z
11
+ date: 2020-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin