Symfony pre_submit reorder fields

Given the following form view, how can I make my second field before submitting? I tried with $form->remove, but I would always get this error:

Warning: Illegal offset type in isset or empty

Not sure how to fix this.

/**
 * @param FormBuilderInterface $builder
 * @param array $options
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('survey', EntityType::class, [
            'class' => SurveyManager::class,
            'attr' => [
                'class' => 'field-change',
            ],
        ])
        ->add('submit', SubmitType::class, [

        ])
        ->addEventListener(
            FormEvents::PRE_SUBMIT,
            function (FormEvent $event) {
                $form = $event->getForm();

                $data = $event->getData();
                $modifier = $data['survey'];
                $form->add('headquarter', EntityType::class, [
                    'class' => HeadQuarterManager::class,
                    'query_builder' => function (HeadQuarterManagerRepository $er) use ($modifier) {
                        return $er->getHeadquarter($modifier);
                    },
                ]);
            }
        );
}
+4
source share
2 answers

Symfony Form does not support reordering form fields. They talked about this feature in releases # 5827 and # 11241 .

You can try to remove the field submitin the EventListener, then add headquerteras well submit(yes, again). But I'm not sure that this will be the work.

IvoryOrderedFormBundle. : position.

0

, , , , {{form_rest (form)}} , .

+1

Source: https://habr.com/ru/post/1657313/


All Articles