A form with different types of checkboxes: a single checkbox for agreements, a checkbox list for preferences, and a constrained checkbox list with minimum and maximum selections.
Every code snippet below is fully editable! Feel free to modify the code, experiment with different values, and see your changes reflected instantly in the live preview on the right.
Use the play button to run different snippet, or the refresh button to restore the original example.
Let's start with an empty form function. This is where we'll build our checkbox form step by step.
First, let's add a single checkbox for a terms and conditions agreement. We use addCheckbox() for individual checkboxes.
isRequired: true property ensures users must check the box to proceed. Now let's add a checkbox list for multiple preferences. We use addCheckboxList() with an array of options.
orientation: 'vertical' stacks the checkboxes vertically. Try changing it to 'horizontal'! Let's add a checkbox list with constraints. The min: 2 and max: 4 properties enforce selection limits.
Sometimes you need specific options to be mandatory within a checkbox list. Add isRequired: true to individual options to make them required.
You can make options conditionally required based on other selections. Use a function for isRequired that references other form values.
isRequired: () => form.get('premium').value)Great job completing this tutorial! You've learned how to work with checkboxes and checkbox lists. Ready to explore other selection fields?
Continue to Number Fields TutorialOther learning paths: