I would like to display the field form.childNumber and form.childFoyerFiscal according to the answer of form.child
If the person chosen TRUE : -- Display"enfantNombre" and "enfantFoyerFiscal"
If the person chosen is FALSE: - Do not display anything
All this must change without refreshing the page (with AJAX for example)
Something like that : ![enter image description here]()
class SimulationType extends AbstractTypepublic function buildForm(FormBuilderInterface $builder, array $options){ $builder /* Partie 1 - Situation */ ->add('situationFamilliale', ChoiceType::class,$this->getConfigurationChoice("Votre situation familliale ?", "input")) ->add('anneeDeNaissance', IntegerType::class,$this->getConfigurationInteger("Quelle est votre année de naissance ?", "input")) ->add('enfant', ChoiceType::class,$this->getConfigurationBoolean("Avez vous des enfants ?", "radioButton")) ->add('enfantNombre', IntegerType::class,$this->getConfigurationInteger("Combien avez-vous d'enfants ?", "input")) ->add('enfantFoyerFiscal', IntegerType::class,$this->getConfigurationInteger("Combien sont encore dans votre foyer fiscal ?", "input")) ->add('pension', ChoiceType::class, $this->getConfigurationBoolean("Payez vous une pension ?", "radioButton")) ->add('pensionPrix', IntegerType::class, $this->getConfigurationInteger("Combien vous coûte cette pension mensuellement?", "input")) /* Partie 2 - Patrimoine */ ->add('residencePrincipale', ChoiceType::class, $this->getConfigurationResidence("Concernant votre résidence principale vous êtes :", "radioButton", "Proprietaire", "Locataire", "Heberge gratuitement")) // Propriétaire ->add('creditResidencePrincipale', ChoiceType::class, $this->getConfigurationBoolean("Avez-vous un crédit sur la résidence principale ?", "radioButton")) // Propriétaire -> Oui ->add('proprietaireCreditPrix', IntegerType::class, $this->getConfigurationInteger("Combien vous coûte ce crédit par mois ?", "input")) ->add('proprietaireCreditTemps', IntegerType::class, $this->getConfigurationInteger("Quelle est la durée restante (en année) ?", "input")) //Locataire ->add('locataireCreditLoyer', IntegerType::class, $this->getConfigurationInteger("Quel est la montant de votre loyer /mois ?", "input")) //Investissement Locatif ->add('investissement_bis', ChoiceType::class, $this->getConfigurationBoolean("Avez-vous déjà un investissement locatif en cours ?", "radioButton")) //Investissement Locatif -> Oui ->add('investissement', CollectionType::class, ['entry_type' => InvestissementType::class, 'allow_add' => true]) // Créer les différents investissements // Credit (Autres qu'immobilier) ->add('credit', ChoiceType::class, $this->getConfigurationBoolean("Avez-vous des crédits? (Autres qu'immobilier)", "radioButton")) //Credit (Autres qu'immobilier) --> Oui ->add('creditAdd', CollectionType::class, ['entry_type' => CreditType::class, 'allow_add' => true]) ->add('revenuMensuel', IntegerType::class, $this->getConfigurationInteger("Quel est le revenu net MENSUEL de votre foyer ?", "input")) /* Partie 3 - Epargne */ ->add('epargne', ChoiceType::class, $this->getConfigurationEpargne("A combien estimez-vous votre épargne?", "radioButton", "Moins de 10.000€", "Entre 10.000€ et 20.000€", "Entre 20.000€ et 50.000€", "Entre 50.000€ et 100.000€", "Plus de 100.000€")) ->add('apportInvestissement', ChoiceType::class, $this->getConfigurationBoolean("Envisagez vous de mettre un apport dans votre investissement?", "radioButton")) // qpportInvestissement -> Oui ->add('apportPrix', IntegerType::class, $this->getConfigurationInteger("Combien apporteriez-vous ?", "input")) ->add('reductionImpot', ChoiceType::class, $this->getConfigurationBoolean("Avez-vous déjà des réductions d'impôts ?", "radioButton")) // reductionImpot -> Oui ->add('reductionImpotPrix', IntegerType::class, $this->getConfigurationInteger("De combien réduisez vous votre impôt par an ?", "input")) /* Partie 4 - Objectifs */ ->add('objectifsPrincipaux', ChoiceType::class, $this->getConfigurationObjectifsPrincipaux("Choisissez vos 3 objectifs principaux", "radioButton", "input", "input1", "input2", "input3", "input4", "input5", "input6")) ->getForm();}public function configureOptions(OptionsResolver $resolver){ $resolver->setDefaults(['data_class' => Client::class, ]);}/** * Permet d'avoir la configuration de base d'un IntegerType * * @param string $label * @param string $class * @return array */private function getConfigurationInteger($label, $class){ return ['label' => $label,'attr' =>['class' => $class ],'required' => true ];}/** * Permet d'avoir la configuration de base d'un button de type RADIO * * @param string $label * @param string $class * @return array */private function getConfigurationBoolean($label, $class): array{ return ['label' => $label,'attr' =>['class' => $class ],'choices' => ['Oui' => true,'Non' => false, ],'expanded' => false,'multiple' => false, ];}/** Permet d'avoir le choix en plusieurs proprositions (Max 5)* L'utilisation de cette function peut servir quand il y a plusieurs choix à faire.**/public function getConfigurationObjectifsPrincipaux($label, $class, $choix1, $choix2, $choix3, $choix4, $choix5, $choix6, $choix7): array{ return ['label' => $label,'attr' =>['class' => $class ],'choices' => [ $choix1 => "patrimoineImmobilier", $choix2 => "antipationRetraite", $choix3 => "reductionFiscalite", $choix4 => "augmentationRendementEpargne", $choix5 => "constitutionCapital", $choix6 => "transmissionEnfant", $choix7 => "revenuComplementaire", ],'expanded' => true,'multiple' => true, ];}/** Configuration de base d'un ChoiceType* Permet d'avoir le choix en plusieurs proprositions (Max 5)* L'utilisation de cette function peut servir quand il y a plusieurs choix à faire.**/public function getConfigurationResidence($label, $class, $choix1, $choix2, $choix3): array{ return ['label' => $label,'attr' =>['class' => $class ],'choices' => [ $choix1 => strtolower(str_replace('','',$choix1)), $choix2 => strtolower(str_replace('','',$choix2)), $choix3 => strtolower(str_replace('','',$choix3)), ],'expanded' => false,'multiple' => false, ];}/** Configuration de base d'un ChoiceType* Permet d'avoir le choix en plusieurs proprositions (Max 5)* L'utilisation de cette function sert quand il y a plusieurs choix à faire.**/public function getConfigurationEpargne($label, $class, $choix1, $choix2, $choix3, $choix4, $choix5): array{ return ['label' => $label,'attr' =>['class' => $class ],'choices' => [ $choix1 => "10k", $choix2 => "20k", $choix3 => "50k", $choix4 => "100k", $choix5 => "1000k", ],'expanded' => false,'multiple' => false, ];}/** * L'utilisation de cette fonction est unique (Partie 1) * * @param $label * @param $class * @return array */private function getConfigurationChoice($label, $class): array{ return ['label' => $label,'attr' =>['class' => $class ],'choices' => ['Célibataire' => 'celibataire','Marié(e)' => 'marie','Pacsé(e)' => 'pacse','En concubinage' => 'concubinage','Divorcé(e)' => 'divorce','Veuf/Veuve' => 'veuf' ] ];}
SimulationController
class SimulationController extends AbstractController/** * @Route("/simulation", name="simulation") * @param Request $request * @param ObjectManager $manager * @return Response */public function formulaire(Request $request, ObjectManager $manager){ $Client = new Client(); $form = $this->createForm(SimulationType::class, $Client); //SimulationType = Formulaire avec les champs /** * Permet d'agir en fonction des résultats des formulaires */ $form->handleRequest($request); dump($Client); /* Est ce que le formulaire est bien valide ? */ if ($form->isSubmitted() && $form->isValid()) { // Si la formulaire est correct --> Direction la page Patrimoine return $this->render('content/verification.html.twig', ['form' => $form->createView()]); } elseif ($form->isSubmitted() && $form->isValid() == false) { // Si la page n'est pas correct, il affiche la page de vérification return $this->render('/content/verification.html.twig', ['form' => $form->createView()]); } else { return $this->render('/content/simulation.html.twig', ['form' => $form->createView()]); }}