PHP code example of martin1982 / mfconditionalfieldsbundle

1. Go to this page and download the library: Download martin1982/mfconditionalfieldsbundle 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/ */

    

martin1982 / mfconditionalfieldsbundle example snippets


// config/bundles.php

return [
    // ...
    Martin1982\MfConditionalFieldsBundle\MfConditionalFieldsBundle::class => ['all' => true],
];



declare(strict_types=1);

namespace App\Form;

use Martin1982\MfConditionalFieldsBundle\Rules\ConditionalRulesInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;


class AttendType extends AbstractType implements ConditionalRulesInterface
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('isAttending', ChoiceType::class, [
                'choices'  => [
                    'Maybe' => 2,
                    'Yes' => 1,
                    'No' => 0,
                ],
            ])
            ->add('reason', TextType::class, [
                'conditional_options' => [
                    'container' => 'reason-container',
                    'action' => self::ACTION_SHOW,
                    'logic' => self::LOGIC_OR,
                    'rules' => [
                        [
                            'name' => 'isAttending',
                            'operator' => self::OPERATOR_IS,
                            'value' => '2',
                        ],
                    ],
                ],
            ])
        ;    
    }
}