Giter VIP home page Giter VIP logo

maroinette.jsonform's Introduction

Marionette.JsonForm Build Status - still work in progress

Marionette.JsonForm is Backbone.Marionette plugin which renders an json as a form as long as each element provides the necessary meta data. The meta-data is described in the json-schema.

The whole point is that sometimes we don't know the structure of the data (the schema) in the front end but we still need to render some complex forms... Or may be it is just difficult to agree with the back-end about the names and types of data elements.

Usage

Here is a short example of how to use the Marionette.JsonForm

var form = new Backbone.JsonForm({
                               "id": "PersonForm",
                               "label": "Person Form",
                               "type": "object",
                               "properties": [
                                 {
                                   "id": "GeneralDetails",
                                   "label": "General Details",
                                   "type": "object",
                                   "properties": [
                                     {
                                       "id": "name",
                                       "label": "Name",
                                       "type": "string",
                                       "value": "Smith"
                                     },
                                     {
                                       "id": "firstName",
                                       "label": "First Name",
                                       "type": "string",
                                       "value": "John"
                                     },
                                     {
                                       "id": "firstName",
                                       "label": "First Name",
                                       "type": "string",
                                       "value": "John"
                                     },
                                     {
                                        "id": "birthDate",
                                        "label": "Birth Date",
                                        "type": "date",
                                        "value": "11-11-1984",
                                        "options": {
                                            "format": "dd-mm-yyyy"
                                        }
                                     }
                                     ]
                                 }
                               ]
                             });

var formView = new Marionette.FormView({
    
    model: form
});

In this example the formView will use the default HTML templates provided with the package. It is possible to override those with your own.

More complex use case is nested forms

{
  "id": "containerForm",
  "type": "object",
  "label": "Container Form",
  "properties": [
    {
      "id": "nestedForm",
      "type": "object",
      "label": "Nested Form",
      "properties": [
        {
          "id": "nestedForm",
          "type": "object",
          "label": "Nested Form",
          "properties": []
        }
      ]
    }
  ]
}

Marionette.JsonForm supports grid layout. The meta-data for the position of each element is in the "options" tag. E.g.

Control layout

{
  "id": "PersonForm",
  "label": "Person Form",
  "type": "object",
  "options": {
    "layout": {
      "type": "grid",
      "cols": "1"
    }
  },
  "properties": [
    {
      "id": "GeneralDetails",
      "label": "General Details",
      "type": "object",
      "options": {
        "layout": {
          "type": "grid",
          "cols": "3",
          "col": 1,
          "row": 1,
          "colspan": 1
        }
      },
      "properties": [
        {
          "id": "name",
          "label": "Name",
          "type": "string",
          "value": "Smith",
          "options": {
            "layout": {
              "col": 1,
              "row": 1,
              "colspan": 1
            }
          }
        },
        {
          "id": "firstName",
          "label": "First Name",
          "type": "string",
          "value": "John",
          "options": {
            "layout": {
              "col": 2,
              "row": 1,
              "colspan": 1
            }
          }
        },
        {
          "id": "birthDate",
          "label": "Birth Date",
          "type": "date",
          "value": "11-11-1984",
          "options": {
            "layout": {
              "col": 3,
              "row": 1,
              "colspan": 1
            },
            "format": "dd-mm-yyyy"
          }
        }
      ]
    }
  ]
}

Supported Form Elements

  • String Input
  • Integer Input
  • Boolean Checkbox
  • Boolean Switch-Button
  • Date
  • SingleSelect
  • MultiSelect
  • Object

Dependencies

  • Backbone.Stickit - v0.9.2
  • Backbone.Validation - v0.7.1
  • Marionette - v2.4.1

Author

Georgi Kosharov

maroinette.jsonform's People

Stargazers

Ivan Kosharov avatar

Watchers

Angel avatar Kosharov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.