EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Form element alignment not working as expected

Open markus-fischbacher opened this issue 7 years ago • 4 comments

Hi there,

just wondering, how to get the fields aligned like EasyAdmin does. Created a form to enter a new password. It's a non-entity form extending the @EasyAdmin/default/layout.html.twig template.

It's looking that way:

image

{% extends '@EasyAdmin/default/layout.html.twig' %}

{% block content_title %}
    {% spaceless %}
        Set Password for User xxx
    {% endspaceless %}
{% endblock %}
{% block main %}
    {{ form(form) }}
{% endblock %}
<?php

namespace App\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;

class NewPasswordType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add(
                'password',
                RepeatedType::class,
                [
                    'first_options' => ['label' => 'Password'],
                    'second_options' => ['label' => 'Repeat password'],
                    'type' => PasswordType::class,
                ]
            )
            ->add('submit', SubmitType::class, ['label' => 'Save password']);
    }
}
    public function setPasswordAction()
    {
        $id = $this->request->query->get('id');
        $user = $this->em->getRepository(User::class)->find($id);

        $form = $this->createForm(NewPasswordType::class);
        $form->handleRequest($this->request);
        if ($form->isSubmitted() && $form->isValid()) {
            $plainPassword = $form->get('password')->getData();
            $password = $this->encoder->encodePassword($user, $plainPassword);
            $user->setPassword($password);
            $this->entityManager->flush();

            return $this->redirectToRoute(
                'easyadmin',
                array(
                    'action' => 'list',
                    'entity' => $this->request->query->get('entity'),
                )
            );
        }

        return $this->render('security/set-password.html.twig', ['form' => $form->createView()]);
    }

How can I get it aligned like the usual EasyAdmin forms are?

image

Any help is appreciated.

Regards Markus

markus-fischbacher avatar Feb 11 '19 09:02 markus-fischbacher

I'm not an expert in Symfony Forms ... but maybe this is fixed if you set the following at the beginning of your Twig template:

{% form_theme form with easyadmin_config('design.form_theme') %}

javiereguiluz avatar Feb 16 '19 16:02 javiereguiluz

I‘ll give it a try. Thanks!

markus-fischbacher avatar Feb 16 '19 16:02 markus-fischbacher

@javiereguiluz I had a similar issue, did it your way and got 'Variable easyadmin not found' error. Solved with a way around creating a "Virtual Entity".

rernesto avatar Apr 07 '19 15:04 rernesto

I'm closing this old issue as hopefully fixed. Thanks.

javiereguiluz avatar Jul 14 '19 11:07 javiereguiluz