- Merge request !45Draft: [#3552451] feat: Name element should scope required state to minimum... → (Open) created by jcandan
When a Name field is made required via #states['required'] on the field’s wrapper (e.g., by Conditional Fields), Drupal’s states.js treats all subcomponents as required on the front-end. The UI shows asterisks on non-minimum components, and the browser can block submission on those optional inputs. Server-side validation already correctly respects minimum components; this is a client-side scoping issue.
#states['required'] to the Name field widget wrapper based on the checkbox.
You could do something like:
function my_module_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
if (!isset($form['field_gate'], $form['field_name'])) {
return;
}
// Put the state on the field wrapper.
$form['field_name']['#states']['required'] = [
':input[name="field_gate[value]"]' => ['checked' => TRUE],
];
}
Actual: Asterisks/HTML required apply to all components (e.g., Middle, Credentials).
Expected: Only minimum components (e.g., Given, Family) are visually required.
Add a small JS behavior to the Name module that listens for the jQuery state:required event on the Name field wrapper/element and re-scopes required UI to minimum components only. This keeps server-side behavior intact and fixes the browser/UI.
Only the Name field’s minimum components show the required asterisk and HTML required when made required via states.
Active
1.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.