I have a form field that is conditionally required depending on another field's value. Using Form API:

<?php
          $form
['details_' . $method['provider'] . '_' . $code]['lastname'] = array(
           
'#type' => 'textfield',
           
'#title' => t('Last Name'),
           
'#disabled' => $disabled,
           
'#states' => array(
             
'visible' => array(':input[name="method"]' => array('value' => $code)),
             
'required' => array(':input[name="method"]' => array('value' => $code))
            ),
          );
?>

The field shows up as required, but somehow fails to respect clientside validation?

Comments

Clientside validation checks for '#required' on the item level, you could try the following

<?php
          $form
['details_' . $method['provider'] . '_' . $code]['lastname'] = array(
           
'#type' => 'textfield',
           
'#title' => t('Last Name'),
           
'#disabled' => $disabled,
           
'#required' => TRUE,
           
'#states' => array(
             
'visible' => array(':input[name="method"]' => array('value' => $code)),
             
'required' => array(':input[name="method"]' => array('value' => $code))
            ),
          );
?>

Yeah that makes it conditional on the frontend, but always required on server-side.

To be sure, you enabled 'Clientside Validation States'?

Status:Active» Postponed (maintainer needs more info)

Status:Postponed (maintainer needs more info)» Active

Same here. There's no clientside validation error but one from serverside after submitting the form. "Clientside Validation States" is enabled. The field is set #required and should only be required if the conditional requirements were hit.

Is a behavior like that the intention behind this submodule or does it affect only #rules validation by design?