1

I have a form without class

class ProfilesSearchType extends AbstractType {

    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
                ->add('disabilityType', 'entity', array(
                    'class' => 'AldenXyzBundle:DisabilityType',
                    'property' => 'name',
                    'multiple' => true,
                    'expanded' => true,
                ))
        ;
    }

called in controller

public function listAction()
{
    $form = $this->createForm(
        new \Alden\XyzBundle\Form\Type\ProfilesSearchType(), array());
    if (isset($_GET['profile_search']))
    {
        $form->bindRequest($request);
        $d = $form->getData();
        // some stuff here
    }
    return array(
        'form' => $form->createView()
    );
}

How to set all checkboxes from disabilityType as checked by default? The class definition is (I deleted setters and getters)

class DisabilityType {

    /**
     * @var integer $disabilityTypeId
     *
     * @ORM\Column(name="disability_type_id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $disabilityTypeId;

    /**
     * @var string $name
     *
     * @ORM\Column(name="name", type="string", length=50, nullable=false)
     */
    private $name;

    /**
     * @var Profile
     *
     * @ORM\ManyToMany(targetEntity="Profile", mappedBy="disabilityType")
     */
    private $profile;

    public function __construct()
    {
        $this->profile = new \Doctrine\Common\Collections\ArrayCollection();
    }
}

2 Answers 2

1

I added in controller

$disabilityDegree = $this->getDoctrine()->
    getRepository("AldenXyzBundle:DisabilityDegree")->findAll();
$form = $this->createForm(new \Alden\XyzBundle\Form\Type\ProfilesSearchType(), array(
        'disabilityType' => new \Doctrine\Common\Collections\ArrayCollection($disabilityType),
            )
    );
Sign up to request clarification or add additional context in comments.

Comments

0

You must initialise your form with all disabilityType

you can do this like that:

$disabilities = $this->getDoctrine()->getRepository("AldenXyzBundle:DisabilityType")-  >findAll();
$form = $this->createForm(new \Alden\XyzBundle\Form\Type\ProfilesSearchType(), $disabilities);

1 Comment

This is not good solution because I use form without class as noted at the beginning.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.