blocknotes / activeadmin_dynamic_fields

ActiveAdmin plugin to add dynamic behaviors to fields

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How make checkbox with toggle fields?

StanZhuravlev opened this issue · comments

Hi!

I see this example for hide fields, if checkbox is set.

f.input :published, input_html: { data: { if: 'checked', action: 'hide', target: '.grp1' } }

But I need make a toggle set of fields depend checkbox: after toggle checkbox a few fields will show, and few is hide. Can I make this with activeadmin_dynamic_fields?

@StanZhuravlev add '.grp1' class to all those items where you want to apply show hide on toggle checkbox.

My question is misunderstanding. :( Once more: for example, I have a TWO set of fields with classes .grp1 and .grp2. And I want toggle a switch, and in one position all elements with class .grp1 are hides, but .grp2 are show. After next toggle, all elements with class .grp1 are show, but .grp2 are hide.

Is it possible?

Sorry for replying so late @StanZhuravlev 😅

You could setup the field to trigger a custom JS function (you can do mostly everything in this way):

f.input :published, input_html: { 'data-function': 'test_fun' }
function test_fun(el) {
  $('.target1').toggleClass('active', el.is(':checked'))
  $('.target2').toggleClass('active', !el.is(':checked'))
}

In the next release I'm adding a syntax for else actions that could be useful in these situations.