M
M
maksustoff2018-04-12 19:33:18
JavaScript
maksustoff, 2018-04-12 19:33:18

Most simple way to generate HTML based on JSON and vice versa?

There is a hierarchical structure of fields (`select,input`), with the ability for the user to combine and nest them into each other. In other words, a tree of logical expressions, where each node-value is several forms of input.
The tree is built by the user and since it needs to be saved into a certain structure and restored back (build HTML) from it. It was advised to use JSON + some JS library to avoid code changes in case of minor form changes.
The HTML looks like this (extra button elements removed for example):

<div class="conditions-group logical-or">

    <div class="conditions">

        <div class="conditions-group logical-and">

            <div class="conditions">
                
                <div class="condition row">
                    <div class="metric">
                        <select class="form-control"></select>
                    </div>
                    <div class="operator">
                        <select class="form-control "></select>
                    </div>
                    <div class="value">
                        <input value="" class="form-control">
                    </div>
                </div>

                <div class="condition row">
                    <div class="metric">
                        <select class="form-control"></select>
                    </div>
                    <div class="operator">
                        <select class="form-control "></select>
                    </div>
                    <div class="value">
                        <input value="" class="form-control">
                    </div>
                </div>

            </div>

            <div class="condition row">
                <div class="metric">
                    <select class="form-control"></select>
                </div>
                <div class="operator">
                    <select class="form-control "></select>
                </div>
                <div class="value">
                    <input value="" class="form-control">
                </div>
            </div>

        </div>
    </div>
</div>

Please help: What can you advise for the implementation of this type of task? If a JS library, which one?
Thank you very much in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-04-12
@webinar

https://github.com/kevinchappell/formBuilder

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question