A form that can add/delete fields (tasks), add/delete subforms (addresses), and add/delete nested fields (phones) at runtime, using simple variables to keep track of counters and IDs.
Every code snippet below is fully editable! Modify the code and see your changes instantly in the live preview on the right.
Use the play button to run a snippet, or the refresh button to restore the original example.
Start with a clean form function. We'll add dynamic behavior step by step.
Add an "Add Task" button that appends a new textbox row each time you click it. Each task also gets a per-item remove button.
Add an address subform each time you click the button, with its own fields and a remove button.
address_1, then call form.addSubform(addressId). Use form.remove(addressId) to delete. Within each address, add a nested phones subform that supports adding/removing phone fields. Use dot paths like address_1.phones.phone_2 to remove specific items.
phone_N IDs and remove them reliably.Great work! Continue learning about organizing complex structures:
Continue to Subforms Tutorial