README.md in activeadmin_dynamic_fields-0.1.2 vs README.md in activeadmin_dynamic_fields-0.1.4

- old
+ new

@@ -4,24 +4,24 @@ Features: - set conditional checks on fields - trigger some actions on other fields -- create links to load some content in a dialogs +- create links to load some content in a dialog -The easiest way to show how this plugin works is looking the examples (below). +The easiest way to show how this plugin works is looking the examples [below](#examples-of-dynamic-fields). ## Install - Add to your Gemfile: `gem 'activeadmin_dynamic_fields'` - Execute bundle - Add at the end of your ActiveAdmin javascripts (_app/assets/javascripts/active_admin.js_): `//= require activeadmin/dynamic_fields` ## Options -Options are passed to fields using *input_html* parameter: +Options are passed to fields using *input_html* parameter as *data* attributes: - **data-if**: check a condition, values: + **checked**: check if a checkbox is checked + **not_checked**: check if a checkbox is not checked + **blank**: check if a field is blank @@ -32,10 +32,11 @@ - **data-target**: target css selector - **data-action**: the action to trigger, values: + **hide**: hides elements + **slide**: hides elements (using sliding) + **fade**: hides elements (using fading) + + **addClass**: adds classes + **setValue**: set a value + **callback**: call a function - **data-value**: value to set - **data-callback**: custom function for setting a value - **data-arg**: argument passed to the custom set function @@ -45,18 +46,22 @@ - A checkbox that hides other fields if false (ex. model *Article*): ```rb form do |f| f.inputs 'Article' do - f.input :published, input_html: { 'data-if': 'not_checked', 'data-action': 'hide', 'data-target': '.grp1' } + f.input :published, input_html: { data: { if: 'not_checked', action: 'hide', target: '.grp1' } } f.input :online_date, wrapper_html: { class: 'grp1' } f.input :position, wrapper_html: { class: 'grp1' } end f.actions end ``` -- Set another field value if a string field is blank: +- Add 3 classes (*first*, *second*, *third*) if a checkbox is true: + +`f.input :published, input_html: { data: { if: 'checked', action: 'addClass first second third', target: '.grp1' } }` + +- Set another field value if a string field is blank (with alternative syntax for data attributes): `f.input :title, input_html: { 'data-if': 'blank', 'data-action': 'setValue', 'data-target': '#article_position', 'data-value': '10' }` - Use a custom function for conditional check (*title_not_empty()* must be available on global scope):