I'm trying to create a form where some of the fields appear or disappear based on the choice the user make inside the first field.
Form Type
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('type', ChoiceType::class, [
'placeholder' => 'Please select the type of difference',
'choices' => array(
'Patch' => 'Patch',
'Regional' => 'Regional',
'Version' => 'Version',
'Platform' => 'Platform',
),
])
->add('maingame', EntityType::class, [
'class' => MainGame::class,
'placeholder' => 'Please select a game',
'choice_label' => 'title',
])
->add('gameversion', EntityType::class, [
'class' => GameVersion::class,
'placeholder' => 'Please select a Main Game first',
'choice_label' => 'title',
])
->add('platform', EntityType::class, [
'class' => Platform::class,
'choice_label' => 'title',
])
->add('text')
->add('nation', EntityType::class, [
'class' => Nation::class,
'choice_label' => 'name',
])
->add('confirm')
;
}
I can't manage to find the right way to do it. Can someone help?
question from:
https://stackoverflow.com/questions/65831291/create-symfony-form-where-fields-appear-and-disappear-based-on-choice 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…