Skip to content

Commit 5fa019b

Browse files
Mattia RoccobertonMattia Roccoberton
authored andcommitted
Removed data-value and data-callback to use only data-action
1 parent b3f597b commit 5fa019b

3 files changed

Lines changed: 11 additions & 13 deletions

File tree

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Options are passed to fields using *input_html* parameter as *data* attributes:
2828
+ **not_blank**: check if a field is not blank
2929
- **data-eq**: check if a field has a specific value
3030
- **data-not**: check if a field hasn't a specific value
31-
- **data-function**: check the return value of a custom function
3231
- **data-target**: target css selector
3332
- **data-action**: the action to trigger, values:
3433
+ **hide**: hides elements
@@ -37,9 +36,8 @@ Options are passed to fields using *input_html* parameter as *data* attributes:
3736
+ **addClass**: adds classes
3837
+ **setValue**: set a value
3938
+ **callback**: call a function
40-
- **data-value**: value to set
41-
- **data-callback**: custom function for setting a value
42-
- **data-arg**: argument passed to the custom set function
39+
- **data-function**: check the return value of a custom function
40+
- **data-arg**: argument passed to the custom set function (as array of strings)
4341

4442
## Examples of dynamic fields
4543

@@ -60,11 +58,11 @@ end
6058

6159
`f.input :published, input_html: { data: { if: 'checked', action: 'addClass first second third', target: '.grp1' } }`
6260

63-
- Set another field value if a string field is blank (with alternative syntax for data attributes):
61+
- Set another field value if a string field is blank:
6462

65-
`f.input :title, input_html: { 'data-if': 'blank', 'data-action': 'setValue', 'data-target': '#article_position', 'data-value': '10' }`
63+
`f.input :title, input_html: { data: { if: 'blank', action: 'setValue 10', target: '#article_position' } }`
6664

67-
- Use a custom function for conditional check (*title_not_empty()* must be available on global scope):
65+
- Use a custom function for conditional check (*title_not_empty()* must be available on global scope) (with alternative syntax for data attributes):
6866

6967
`f.input :title, input_html: { 'data-function': 'title_empty', 'data-action': 'slide', 'data-target': '#article_description_input' }`
7068

@@ -76,7 +74,7 @@ function title_empty( el ) {
7674

7775
- Call a callback function as action:
7876

79-
`f.input :published, input_html: { 'data-if': 'checked', 'data-action': 'callback', 'data-callback': 'set_title', 'data-args': '["[unpublished]"]' }`
77+
`f.input :published, input_html: { data: { if: 'checked', action: 'callback set_title', args: '["Unpublished !"]' } }`
8078

8179
```js
8280
function set_title( args ) {

app/assets/javascripts/activeadmin/dynamic_fields.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ function dfSetupField( el ) {
5858
else target.fadeOut();
5959
});
6060
}
61-
else if( action == 'setValue' ) {
62-
var val = el.data( 'value' ) ? el.data( 'value' ) : '';
61+
else if( action.substr( 0, 8 ) == 'setValue' ) {
62+
var val = action.substr( 8 ).trim();
6363
if( dfEvalCondition( el, args ) ) dfSetValue( target, val );
6464
el.on( 'change', function( event ) {
6565
if( dfEvalCondition( $(this), args ) ) dfSetValue( target, val );
6666
});
6767
}
68-
else if( action == 'callback' ) {
69-
var cb = el.data( 'callback' );
68+
else if( action.substr( 0, 8 ) == 'callback' ) {
69+
var cb = action.substr( 8 ).trim();
7070
if( cb && window[cb] ) {
7171
if( dfEvalCondition( el, args ) ) window[cb]( el.data( 'args' ) );
7272
el.on( 'change', function( event ) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module ActiveAdmin
22
module DynamicFields
3-
VERSION = '0.1.4'
3+
VERSION = '0.1.5'
44
end
55
end

0 commit comments

Comments
 (0)