Within my angular application, I am faced with the task of implementing a complex form. Users should be able to dynamically add, remove, and modify elements within the form.
Each element consists of a group of inputs, where some are conditionally hidden or visible based on the selection of dropdowns within the group. These conditional groups may have varying quantities of fields, with some being required and others not.
No new array element can be added until all visible fields are validated. Additionally, the entire form needs to be easily serialized and deserialized for backend storage.
I believe that utilizing form arrays is the way to go. I have explored some third-party libraries like ng dynamic forms, but I am still unsure how to achieve what I require. Any suggestions on how I can implement this?
https://i.sstatic.net/HKlEx.png
The form is intended for adding, editing, and removing the following objects:
tasks": [
{
"uuid": "4e7e6737-8557-4a05-bb78-808f8a10daa4",
"created": "2018-12-17T15:19:07.328408+01:00",
"title": "TITLE (first input)",
"modified": "2018-12-17T15:19:07.328440+01:00",
"task_type": "SEND_EMAIL",
"time_value": 2,
"time_unit": "DAYS",
"time_dir": "BEFORE",
"process": "5f185517-40df-43e8-b677-3cf929b21638",
"config": {
"uuid": "b21f4cdf-22ba-42cd-81fa-7e7f1f84e6d1",
"created": "2018-12-17T15:20:25.350927+01:00",
"modified": "2018-12-17T15:20:25.350948+01:00",
"email_title": "Email title",
"email_from_address": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b6d3ced7dbc6dad3f6d3ced7dbc6dad398d5d9db">[email protected]</a>",
"email_from_name": "Hello",
"email_content": "Email body",
}
}
],
The dropdown options for the task type include:
- "SEND EMAIL" - displaying fields such as "Email title", "Email from", "Email content" when selected.
- "CREATE EVENT" - displaying fields like "Event date and time", "Event duration" when selected.
During deserialization of the form, each task's "config" object will contain specific fields based on the selected type.