PHP code example of oveleon / contao-be-field-dependency

1. Go to this page and download the library: Download oveleon/contao-be-field-dependency library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

oveleon / contao-be-field-dependency example snippets


'field1'  => [
    'exclude'    => true,
    'inputType'  => 'checkbox',
    'eval'       => ['tl_class' => 'w50 m12'],
    'sql'        => "char(1) NOT NULL default '0'",
],
'field2'  => [
    'exclude'    => true,
    'inputType'  => 'text',
    'eval'       => ['maxlength'=>64, 'tl_class'=>'w50'],
    'sql'        => "varchar(64) NOT NULL default ''",
    'dependsOn'  => [
        'field1' => 1 // Displays this field only if the checkbox (field1) has been selected.
    ]
],

'field2'  => [
    'exclude'    => true,
    'inputType'  => 'text',
    'eval'       => ['maxlength'=>64, 'tl_class'=>'w50'],
    'sql'        => "varchar(64) NOT NULL default ''",
    'dependsOn'  => [
        'field1' => static function($fieldName, $objModel) {
            // $fieldName = field1
            // "field1" is automatically supplemented with the field evaluation "submitOnChange = true" (autoSubmit = true).
            
            // Return true = show / false = hide
            return $objModel->{$fieldName} == 1;  
        }
    ]
],

'field2'  => [
    'exclude'    => true,
    'inputType'  => 'text',
    'eval'       => ['maxlength'=>64, 'tl_class'=>'w50'],
    'sql'        => "varchar(64) NOT NULL default ''",
    'dependsOn'  => [
        static function($fieldName, $objModel, &$arrEvaluationFields) {
            // $fieldName = 0
            // 'field1' must be extended independently with the field evaluation 'submitOnChange = true' or added via the third parameter ($arrFields) (autoSubmit = true).
            $arrEvaluationFields[] = 'field1';
            
            // Return true = show / false = hide       
            return $objModel->field1 == 1; 
        }
    ]
],

'field1'  => [
    'exclude'    => true,
    'inputType'  => 'checkbox',
    'eval'       => ['tl_class' => 'w50 m12'],
    'sql'        => "char(1) NOT NULL default '0'",
],
'field2'  => [
    'exclude'    => true,
    'inputType'  => 'checkbox',
    'eval'       => ['tl_class' => 'w50 m12'],
    'sql'        => "char(1) NOT NULL default '0'",
],
'field3'  => [
    'exclude'    => true,
    'inputType'  => 'text',
    'eval'       => ['maxlength'=>64, 'tl_class'=>'w50'],
    'sql'        => "varchar(64) NOT NULL default ''",
    'dependsOn'  => [
        'field2' => 1, 
        'field3' => 1 // Both fields must be checked to display this field
    ]
],