Category : symfony-forms

I have custom Form Type: class ChoosyType extends AbstractType { private EntityManagerInterface $entityManager; public function __construct(EntityManagerInterface $entityManager) { $this->entityManager = $entityManager; } public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) { $form = $event->getForm(); $parentForm = $form->getParent(); $data = $event->getData(); $newChoices = $this->createNewChoices($options[‘choices’]); $parentForm->add($form->getName(), ChoosyType::class, array_replace($options, [ ‘choices’ => $newChoices, ..

Read more

I have a Product object which holds a collection of Colorway objects. I’m using a Symfony embedded form to edit the entire collection of Colorways for a single Product at once, allowing adding and removing of Colorway objects. class ColorwaysFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add(‘colorways’, CollectionType::class, [ ..

Read more

I have a question, im trying to get a multiple choice field from a different entity than the main form entity to work. I have more than 1 table in my database, and the main table, lets call it "person" requires that the form rendering includes several multiple options from different entities than its own. ..

Read more

I am having issues overriding a label in my form in my Symfony 4.4 application: {{ form_row(form.legal, { ‘label’ : ‘personal.form.fields.legal’|trans }) }} personal.form.fields.legal looks like this: I agree that I am 18 and above, I have read and accept the <a href="/terms-cond">T&Cs</a> My attempt at overriding this label is this: {% block _crmbundle_personal_legal_label %} ..

Read more