States don't work for a block rendering a form I created a block in which I called a form inside the build() function.
The form class has elements like radio button, input field type number, and submit button. I added a state condition to make the number field and submit button only visible on a certain condition of radio button.
The submission button is working correctly based on state condition, but not the number input field.
Does anyone has any idea?
$form['age'] = [
  '#type' =&gt; 'number',
  '#min' =&gt; 0,
  '#title' =&gt; $this-&gt;t('age'),
  '#default_value' =&gt;'',
  '#states' =&gt; [
    'visible' =&gt; [
      [':input[name=&quot;marital_status&quot;]' =&gt; [['value' =&gt; 'single'],['value'=&gt;'couple']]],
    ]
  ],
];

$form['mybutton'] = [
  '#type' =&gt; 'submit',
  '#value' =&gt; $this-&gt;t('button'),
  '#states' =&gt; [
    'visible' =&gt; [
      [':input[name=&quot;marital_status&quot;]' =&gt; [['value' =&gt; 'single'],['value'=&gt;'couple']]],
    ]
  ],
];

$form['marital_status'] = [
  '#type' =&gt; 'radios',
  '#title' =&gt; $this-&gt;t('Marital status'),
  '#options' =&gt; [
    'single' =&gt; $this-&gt;t('single'),
    'couple' =&gt; $this-&gt;t('couple')
  ]
];
I had to override the twig files for the form-element so some classes were missing like js-form-item' and 'form-item'. After adding thoses classes in the twig file,  the states worked.