- Issue created by @trzcinski.t@gmail.com
- Merge request !53538078: Fixes the problem with reading the flat array of user input for nested arrays → (Merged) created by Unnamed author
Automatically closed - issue fixed for 2 weeks with no activity.
The VirtualSelect form element does not work for forms with nested structures.
This is because of the vallueCallback method, that does not take into account the form structure, by not utilizing the parents , when getting the value from userInput:
public static function valueCallback(&$element, $input, FormStateInterface $form_state): mixed {
$fieldName = $element['#name'] . '-input';
$form_state->addCleanValueKey($element['#name'] . '-input');
return $form_state->getUserInput()[$fieldName] ?? [];
}
In the code above, we do not dig into the array structure properly.
Create a custom form where you set the virtual_select element in the nested structure:
$form = [];
$form['#tree'] = TRUE;
$form['wrapper'] = [
'#type' => 'details',
];
$form['wrapper']['select'] = [
'#type' => 'virtual_select',
]
Fix the valueCallback so that it uses:
- first the input parameter if not empty
- then the nested structure of the form, by using $element['#parents']
Implement
None
None
None
Active
1.0
Code
Automatically closed - issue fixed for 2 weeks with no activity.