Verwendung: Custom Elements: 'dependsOn' innerhalb 'list'

Andreas's Avatar

Andreas

01 Oct, 2022 05:59 PM

Produkt: Custom Elements Contao
Contao-Version: 4.19

Hallo Rocksolid-Team,

ich möchte für TAO ein komplexes Inhaltselement mit den RSCE erstellen. Dies soll auf der Basis des "Boxes"-Elements aufgebaut werden. Allerdings sollen die Boxen eine unterschiedliche Inhaltsstruktur nach Wahl haben können.

Die Auswahl der 'inputType' per 'select' über 'dependsOn' klappt auch grundsätzlich.
Sobald ich die Blocks aber in ein 'list' packe, wird das 'dependsOn' nicht mehr ausgewertet.

Das erscheint mir auch logisch, da durch 'list' eine Array-Ebene hinzukommt.

Die Frage ist also: Wie muss 'field' lauten, damit 'value' ausgewertet wird?

...
'dependsOn' => ['field' => ??? ,'value' => '1'],
...
Das Schema soll wie folgt aussehen (es gibt mehr Blocktypen und die einzelnen Blocks sind auch komplexer aufgebaut):
return [
    'label' => ['Unterschiedliche Blocks', ''],
    'types' => ['content'],
    'standardFields' => ['cssID'],   
    'fields' => [
        'blocks' => [
            'label' => ['Blocks', ''],
            'elementLabel' => '%s. Block',
            'inputType' => 'list',
            'minItems' => 3,
            'maxItems' => 3, 
            'fields' => [    
                'blockType' => [
                    'label' => ['Dieser Block  ist ein:', ''],
                    'inputType' => 'select',
                    'options' => [
                        '0' => 'Bitte auswählen',
                        '1' => 'Textblock',
                        '2' => 'Bildblock ',
                    ],
                    'eval' => ['submitOnChange'=>true, 'tl_class'=>'w50'],
                ],
                
                'blockTxt' => [
                    'label' => ['Text', ''],
                    'inputType' => 'text',
                    'eval' => [...],
                    'dependsOn' => [
                        'field' => ['blocks' => 'blockType'],
                        'value' =>'1'
                    ],                                                  
                ],

                'blockImg' => [
                    'label' => ['Bild', ''],
                    'inputType' => 'fileTree',
                    'eval' => [...],
                    'dependsOn' => [
                        'field' => ['blocks' => 'blockType'],
                        'value' =>'2'
                    ],                                                  
                ],
            ],
        ],
    ],
]

Danke und viele Grüße
Andreas

  1. 1 Posted by Andreas on 02 Oct, 2022 06:07 AM

    Andreas's Avatar

    Hat sich erledigt.

    Es funktionierte, nachdem ich aus den options des select die Option

    '0' => 'Bitte auswählen',
    
    entfernt und stattdessen die 'includeBlankOption' zum select hinzugefügt hatte.
    'dependsOn' lautet dann ganz normal:
    ...
    'dependsOn' => [
      'field' => 'blockType',
      'value' =>'1'
    ],
    ...

    Ein Basisschema für ein Element könnte dann z.B. so aussehen:

    return [
        'label' => ['Unterschiedliche Blocks', ''],
        'types' => ['content'],
        'standardFields' => ['cssID'],
    'fields' => [ 'blocks' => [ 'label' => ['Blocks', ''], 'elementLabel' => '%s. Block', 'inputType' => 'list', 'minItems' => 1, 'maxItems' =>12, 'fields' => [
    'blockType' => [ 'label' => ['Dieser Block ist ein:', 'Bitte auswählen'], 'inputType' => 'select', 'options' => [ '1' => 'Textblock', '2' => 'Bildblock ', ], 'eval' => [ 'submitOnChange'=>true, 'includeBlankOption' => true, 'tl_class'=>'w50', ], ],

            'blockTxt' => [
                'label' => ['Text', ''],
                'inputType' => 'text',
                'eval' => ['tl_class' => 'w50'],
                'dependsOn' => [
                    'field' => 'blockType',
                    'value' =>'1',
                ],                                                  
            ],
    
            'blockImg' => [
                'label' => ['Bild', ''],
                'inputType' => 'fileTree',
                'eval' => [
                    'fieldType' => 'radio',
                    'filesOnly' => true,
                    'extensions' => \Config::get('validImageTypes'),
                ],
                'dependsOn' => [
                    'field' => 'blockType',
                    'value' =>'1',
                ],                                                  
            ],
        ],
    ],
    
    
    
    
    ];

    Danke und Gruß
    Andreas

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac