Generating HTML forms from JSON or XML feed using JQuery

后端 未结 2 1740
遥遥无期
遥遥无期 2020-12-02 23:42

I would like to create an HTML form based on XML or JSON data using Jquery and I also plan to validate any form fields that may be empty or incorrect.

I would like

相关标签:
2条回答
  • 2020-12-03 00:16

    I've found some of these that might help you:

    Generating forms from JSON schema:

    • how to create a html form using a JSON definition?
    • http://neyric.github.com/inputex/examples/json-schema.html
    • JavaScript to generate/render dynamic HTML form from JSON or similar data?
    • Any tool to generate html form

    Generating forms from an XML schema:

    • http://www.totallysmartit.com/examples/xml/questionnaire/
    • Create HTML form from XML
    • http://www.datamech.com/XMLForm/

    Samples from different libraries to generate form:

    • http://www.alpacajs.org/examples.html
    • http://jsonforms.io/#/examples
    • http://schemaform.io/examples/bootstrap-example.html
    0 讨论(0)
  • 2020-12-03 00:38

    Just to give you another choice, a library I created:

    https://github.com/brutusin/json-forms

    JSON Schema to HTML form generator, supporting dynamic subschemas (on the fly resolution). Extensible and customizable library with zero dependencies. Bootstrap add-ons provided

     var bf = brutusin["json-forms"].create({
      "$schema": "http://json-schema.org/draft-03/schema#",
      "type": "object",
      "properties": {
        "s1": {
          "type": "string",
          "title": "A string",
          "description": "A string input"
        },
        "num1": {
          "type": "integer",
          "title": "A number",
          "minimum": 1,
          "maximum": 10,
          "multipleOf": 3,
          "description": "An integer multiple of `3`, between `1` and `10` (inclusive)"
        },
        "array1": {
          "type": "array",
          "title": "An array values",
          "items": {
            "type": "object",
            "properties": {
              "value": {
                "type": "string",
                "title": "Value"
              }
            }
          }
        }
      }
    });
    var container = document.getElementById('container');
    bf.render(container);
    <link rel="stylesheet" href='https://cdn.jsdelivr.net/brutusin.json-forms/1.3.2/css/brutusin-json-forms.min.css'/>
    <link rel="stylesheet" href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'/>
    <script src="https://code.jquery.com/jquery-1.12.2.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/brutusin.json-forms/1.3.2/js/brutusin-json-forms.min.js"></script>
    <script src="https://cdn.jsdelivr.net/brutusin.json-forms/1.3.2/js/brutusin-json-forms-bootstrap.min.js"></script>
    <div id="container"></div>
    <hr>
    <button class="btn btn-primary" onclick="alert(JSON.stringify(bf.getData(), null, 4))">getData()</button>&nbsp;<button class="btn btn-primary" onclick="if (bf.validate()) {alert('Validation succeeded')}">validate()</button>

    More live examples at http://brutusin.org/json-forms

    0 讨论(0)
提交回复
热议问题