Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138163

How to submit a form with a list of related fields?

$
0
0

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.

I made a simple demonstration here

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 that:

{
    {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?


Viewing all articles
Browse latest Browse all 138163

Trending Articles