A
A
Alexander2018-05-10 16:58:53
JavaScript
Alexander, 2018-05-10 16:58:53

Generate form from JSON?

I still don't quite understand if this can be done at all?
There is a large form that consists of input, select, switch
The client wants the presence of fields to be determined by JSON. And at the same time, each select sent separate requests.
I don't quite understand how this can be implemented.
That is, I receive a request, such as

"fields": {
        "autombile": {
            "brand": {
                "label": "brand",
                "name": "brand",
                "dependence": "",
                "type": "select"
                "active": true
            }
            .
            .
            .
            "name": {
                "label": "name",
                "name": "name",
                "dependence": "",
                "type": "input"
                "active": true
            },
            "age": {
                "label": "age",
                "name": "age",
                "dependence": "",
                "type": "input"
                "active": true
            },
            "switch": {
                "label": "switch",
                "name": "switch",
                "dependence": "",
                "type": "input"
                "active": true
            }
        }
}

There, for example, 10 select elements are displayed, when I open one of these elements, it must send its request and receive a response for this very select, is this correct at all?
And if so, how can this be done? Given that there may be input type number/text/radio and select

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2018-05-10
@webinar

Here a lot depends on the architecture and api, but in addition to "fields" you can also receive "url".

"brand": {
                "label": "brand",
                "name": "brand",
                "dependence": "",
                "type": "select"
                "active": true,
                'items' => '/url/to/items/json?id=brand'
            }

I think it will be correct to check items for the presence of an object, so as not to throw a request if the data has already been received. Something like this.

A
Alexey Shashenkov, 2018-05-11
@teknik2008

I don't see the difficulty. Write everything on different components, for each list item
https://jsfiddle.net/825x4bj3/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question