jeudi 17 mars 2016

ZF2 Create parent checkbox for multi-checkbox

I've managed to create a multi-checkbox using Zend\Form. Now I have to create a "parent" checkbox. The expected result is quite close from this:

enter image description here

The "Parent 1" action will be to check all childs. This task will be done by JQuery (I guess), but is there a way to generate this pattern using ZF2 form? Or should I manually create the "parent" checkbox with JQuery too (which is quite ugly in my opinion)?

My code for "single level" multi-box:

Controller action:

public function addAction()
{
    $form = new RoleForm();      

    $formattedRights = getStuffFromDb();

    $form->get('rights')->setAttribute('options', $formattedRights);

    return array(
        'form' => $form,
    );
}

Zend Form:

    ...
    $this->add(array(
        'type' => 'Zend\Form\Element\MultiCheckbox',
        'name' => 'rights',
        'options' => array(
            'label' => 'Associated rights',
        )
    ));
    ...




Aucun commentaire:

Enregistrer un commentaire