user1746732
user1746732

Reputation:

Embed collection of form

I'm stuck with an embed collection of form.

I have a Holiday form consisting of three fields : a name, a begin and an end. Note that begin and end are managed by Bootstrap date-time picker

Holiday Form

Then I have a Grade Form consisting of some fields and a collection of Holiday Form. The javascript part to add or delete a Holiday Form works fine.

Grade From

As you can see in this image, the begin and end icon are not shown. But this is not all, the date-time picker doesn't works. I have find out that the data-prototype given by symfony is not complete, some classes are missing.

Should I add an option or something else in my Types to make it works ?

EDIT :

My GradeType :

public function buildForm(FormBuilderInterface $builder, array $options) {
    $builder->add('name');
    $builder->add('campus', 'entity',
        [
        'class' => 'Ent\HomeBundle\Entity\Campus',
        'property' => 'name',
        'query_builder' => function(\Doctrine\ORM\EntityRepository $er) use ($options) {
                $qb = $er->createQueryBuilder('c');
                if ($this->controller->getCurrentUser()->getGroup()->getRole() == 'ROLE_ADMIN') {
                    $qb->where($qb->expr()->in('c', ':campuses'))
                       ->setParameter('campuses', $this->controller->getCurrentUser()->getCampuses()->toArray());
                }
                return $qb;
            }
        ]
    );
    $builder->add('school', 'entity', [
        'class' => 'Ent\HomeBundle\Entity\School',
        'property' => 'name'
        ]
    );
    $builder->add('holidays', 'collection',
        [
        'type'         => new HolidayType($this->controller),
        'allow_add'    => true,
        'allow_delete' => true,
        'by_reference' => false
        ]
        );
}

My HolidayType :

public function buildForm(FormBuilderInterface $builder, array $options) {
    $builder->add('name');
    $builder->add('begin', new DatePickerType(), ['help' => 'Only the day and the month will be used']);
    $builder->add('end', new DatePickerType(), [
        'required' => false,
        'help' => 'Only the day and the month will be used',
        ]
    );

     $builder->addEventListener(FormEvents::POST_BIND, array($this, 'isEndValid'));
}

Upvotes: 2

Views: 369

Answers (1)

jovobe
jovobe

Reputation: 763

The datepicker is not working because you add the datepicker fields via javascript. You have to call something like

$('.datepicker').datetimepicker({
    format: 'dd/MM/yyyy hh:mm:ss'
});

when you add the new rows from the prototype. By calling .datetimepicker() you enable the datepicker for the selected field.

Concerning the missing classes You have to post the content of the DatePickerType.

Upvotes: 1

Related Questions