Question about composite conditional fields

Created on 24 February 2023, over 1 year ago

I've created a custom composite field based on the example module. The form has some conditional fields which should become visible and required when other fields meet certain conditions.

To make a field visible AND required I have duplicated the code in the AfterBuild function

$element['#states']['visible'] = [
  [':input[name="' . $composite_name . '[field_extra]"]' => ['value' => "Yes"]],
];
$element['#states']['required'] = [
  [':input[name="' . $composite_name . '[field_extra]"]' => ['value' => "Yes"]],
];

Is this the correct way to do this? Or are there ways to combine 'visible' and 'required' so the requirements are only needed to state once?

πŸ’¬ Support request
Status

Closed: works as designed

Version

6.1

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands marcom2021

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024