How do I make a form field go back invisble after I uncheck a radio button? I'm currently building a form where the goal is that the administrator will have to choose between 3 radio buttons. If one click on any of the radios, a specific field shows up (There are 3 fields set as "invisible"). My issue is that, I have no problem making these fields show up, but they don't disappear if I select something else.

Here is my code:

function walk_handler_form_alter (&amp;$form, FormStateInterface &amp;$form_state, $form_id)
{
  $form['field_prestation_walk']['#states'] = [
  'visible' =&gt; [
    ':input[name="field_prestation_type"][value="walk"]' =&gt; [
        'checked' =&gt; true
      ]
    ]
  ];
}


So, as I said earlier, this code makes my forms show when I click on their related radios. However, if I click on another radio, they don't disappear.

I had a lot of troubles to find some documentation about that (well, I found some, but the examples given wheren't thorough enough for me). Also, I tried to add an invisible after the visible one, with the exact condition except that 'checked' was set to false, but it didn't work.

Should I use plain Javascript / jQuery for this, or am I just it the wrong way?

Thanks in advance
Hello try this ... 

$form['field_prestation_walk']['#states'] = [
  'visible' =&gt; [
    ':input[name="field_prestation_type"]' =&gt; [
        'value' =&gt; 'walk'
      ],
    ]
  ];