Checkbox for checking/unchecking all checkboxes

Do you know of a better way to create this functionality?

I have a list of task, where each task has it’s own checkbox (Ugn 41, Ugn 42, etc). I have added a single checkbox that with a script checks/unchecks all the checkboxes of the list (Checkbox “Alla”). The user can then with one checkbox check/uncheck all the tasks at the same time. I further added a function so that if the user unchecks one of the tasks manually, the checkbox that can check/uncheck all task, is then unchecked as well.

image

The way I did this was first by creating a template for the task, since the amount of tasks shall be dynamic. I then populated a flex repeater with a number of forementioned task-templates. (In the image, Ugn 41, Ugn 42, and so on, are inside the flex repeater). The check/uncheck all checkbox was added manually to the view. Since I can’t get to properties of components in a flexrepeater (other than through params) I added the script that registers clicks of the checkbox in the template and let it set the state of a session param which I bound to the check/uncheck all checkbox.

My solution works fine, but it feels like the flex repeater makes me run laps around it all to get the functionality I want.

So any one that made this functionality in cleaner manner?