In my project, I am utilizing Aurelia to create a dynamic form based on a JSON data. The form is being generated from a JSON structure similar to the one shown below:
Schema = [{
'key': 'Name',
'display': 'Name',
'type': 'text',
'placeholder': 'Name',
'required': true
},
{
'key': 'IsSubscribed',
'display': 'Subscribed to newsletter?',
'type': 'checkbox',
'placeholder': null,
'required': false
}];
The model required to fill in the form is accessible via a Web API service. So far, I have managed to successfully implement the following template.
<template>
<section class="au-animate">
<h2>Edit Form</h2>
<form class="form-group">
<div repeat.for="item of Schema" class="form-group">
<label if.bind="item.type === 'text' || item.type === 'checkbox'" class="control-label" for.bind="item.key">${item.display}
<input class="form-control" id.bind="item.key" placeholder.bind="item.placeholder" type.bind="item.type" value.bind="Model[item.key]" />
</label>
<label if.bind="item.type === 'textarea'">${item.display}
<textarea placeholder.bind="item.placeholder" value.bind="Model[item.key]></textarea>
</label>
...
</div>
</form>
</section>
</template>
However, I am currently encountering challenges when the Model contains another object as a property. For instance, for the Address property, I would like to include an input field specifically for City.
This leads to a scenario where item.key = "Address.City"
.
I am unable to bind with either (1) Model.Address.City or (2) Model['Address']['City'] since the form is dynamically generated at runtime. My aim is to use something like (3) Model['Address.City'], allowing me to utilize Model[item.key] for binding. Is there a straightforward syntax to achieve this?
An example of a similar application using Angular JS can be found at: Angular Schema Form
Thank you for any assistance provided in advance.