jeudi 19 février 2015

Add a select all option to a list of checkboxes in symfony

Im relatively new to web development and html forms. In my webapp i have a list (of gpstracks) and each list entry has a checkbox so the user can edit, delete, download, whatever... all selected tracks at once. In order to increase usability i would like to add an "select all" button or checkbox, that automatically checks all other checkboxes in the form (preferably without reloading the entire form).


Is there any possibility at all to do this? I have been trying to use



$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($tracks){

$form = $event->getForm();

foreach($tracks as $track)
{
$form->get($track->getId())->setData(array('checked'=>true));
}
}


in combination with a second button of the type 'submit' that reads 'select all'. Obviously, this reloads the entire form. But after the reload all checkboxes remain unchecked, so the setData method seems to have no effect at all.


Is there any option to programmatically check checkboxes checkboxes in a form, preferably even without reloading the entire form?





Aucun commentaire:

Enregistrer un commentaire