Issue
My goal:
Based on a multi select option, I'd like to show another field.
I've added 4 fields through the studio:
- test1_c (text field)
- test2_c (text field)
- singleselect_c (drop down)
- optionfield_c (multi select)
The drop down and the multi select both use the same list:
Then, I add the code:
sudo -u www-data vi extensions/myExtension/modules/Accounts/Service/FieldDefinitions/OptionFieldDisplayLogicMapper.php
<?php
namespace App\Extension\myExtension\modules\Accounts\Service\FieldDefinitions;
use App\FieldDefinitions\Entity\FieldDefinition;
use App\FieldDefinitions\LegacyHandler\FieldDefinitionMapperInterface;
class OptionFieldDisplayLogicMapper implements FieldDefinitionMapperInterface
{
public function getKey(): string
{
return 'optionfield-display-logic-mapper';
}
public function getModule(): string
{
return 'accounts';
}
public function map(FieldDefinition $definition): void
{
$vardefs = $definition->getVardef();
if (isset($vardefs['test1_c'])) {
$vardefs['test1_c']['displayLogic']['show_only_if_test1_selected'] = [
'key' => 'displayType',
'modes' => ['detail', 'edit', 'create'],
'params' => [
'fieldDependencies' => ['optionfield_c'],
'targetDisplayType' => 'none',
'activeOnFields' => [
'optionfield_c' => [
['operator' => 'not-equal', 'values' => ['test1']],
],
],
],
];
}
if (isset($vardefs['test2_c'])) {
$vardefs['test2_c']['displayLogic']['show_only_if_test2_selected'] = [
'key' => 'displayType',
'modes' => ['detail', 'edit', 'create'],
'params' => [
'fieldDependencies' => ['optionfield_c'],
'targetDisplayType' => 'none',
'activeOnFields' => [
'optionfield_c' => [
['operator' => 'not-equal', 'values' => ['test2']],
],
],
],
];
}
$definition->setVardef($vardefs);
}
}
and clear the cache:
sudo -u www-data /usr/bin/php8.4 bin/console cache:clear
If I replace optionfield_c with singleselect_c in the code, it's working.
I can select the option and the correct field is being displayed (right away, without saving the record).
If I use optionfield_c from the multi select and have nothing selected, it's all good:
If I edit the record and select test 1, nothing happens :( :
(no error in the browser console as well)
After saving the record, both text fields show up :( :
Possible Fix
No response
Steps to Reproduce the Issue
Context
No response
Version
8.10.2
What browser are you currently using?
Firefox
Browser Version
No response
Environment Information
MariaDB, PHP 8.4
Operating System and Version
Ubuntu 24
Issue
My goal:
Based on a multi select option, I'd like to show another field.
I've added 4 fields through the studio:
The drop down and the multi select both use the same list:
Then, I add the code:
sudo -u www-data vi extensions/myExtension/modules/Accounts/Service/FieldDefinitions/OptionFieldDisplayLogicMapper.phpand clear the cache:
sudo -u www-data /usr/bin/php8.4 bin/console cache:clearIf I replace
optionfield_cwithsingleselect_cin the code, it's working.I can select the option and the correct field is being displayed (right away, without saving the record).
If I use
optionfield_cfrom the multi select and have nothing selected, it's all good:If I edit the record and select test 1, nothing happens :( :
(no error in the browser console as well)
After saving the record, both text fields show up :( :
Possible Fix
No response
Steps to Reproduce the Issue
Context
No response
Version
8.10.2
What browser are you currently using?
Firefox
Browser Version
No response
Environment Information
MariaDB, PHP 8.4
Operating System and Version
Ubuntu 24