I could not think of a better title, but the problem is: I have a form for Users and the user can have one or many phone numbers. More phone fields is added via a js script, so the number of phone fields is arbitrary. I want to group these fields into a unique list of objects.
Example (check it here):
<form method="post" action="#" class="container">
<div class="form-group row">
<label for="name" class="control-label">Name</label>
<input type=text name="name" class="form-control" />
</div>
<fieldset id="phones" name="phones" class="form-row">
<div class="form-group col-sm-2 clonable">
<label for="label" class="control-label">Label</label>
<input type=text name="label" class="form-control" />
</div>
<div class="form-group col-sm-2 clonable">
<label for="number" class="control-label">Phone</label>
<input type=text name="number" class="form-control" />
</div>
<div class"form-group col-sm-1">
<input id="btnaddphone" type="button" value="Add" class="btn btn-primary" />
</div>
</fieldset>
<div class="form-group row">
<input type="submit" value="Submit" class="btn btn-success col-sm-2" />
</div>
</form>
What I want is submit this form structured like the following json
{
{name: "name", value: "..."},
{name: "phones", value: [
{name: "label", value: "..."}, {name: "number", value: "..."},
{name: "label", value: "..."}, {name: "number", value: "..."}, ...
]}
}
And not like the default:
{
{name: "name", value: "..."},
{name: "label", value: "..."}, {name: "number", value: "..."},
{name: "label", value: "..."}, {name: "number", value: "..."}, ...
}
Is there a simple way to do this with just HTML/JS?
If not, is there a way to configure it in a razor page for ASP.NET MVC?