Coder Social home page Coder Social logo

aptible / ember-json-schema-views Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 6.0 158 KB

A collection of Ember.js form components for aptible/ember-json-schema-document

License: MIT License

JavaScript 91.81% HTML 2.25% SCSS 2.40% Handlebars 3.54%
aptible-enclave aptible-deploy

ember-json-schema-views's Introduction

ember-json-schema-views

This addon extends aptible/ember-json-schema-document with basic JSON Schema-driven form components.

The following JSON Schema property types are supported:

  • boolean using schema-field-radio or schema-field-toggle
  • enum using schema-field-select
  • text using schema-field-text

Schema properties can be recursed using the each-property component.

Example: Generating a Schema-driven form by recursing Schema properties

The following template will iterate a schema's properties and build UI components that are bound to corresponding document values;

var schema = new Schema(jsonBlob);
var document = schema.buildDocument();
var properties = schema.properties();
{{#each-property properties=properties as |key property type|}}
  <label>{{property.displayProperties.title}}</label>
  {{component (concat 'schema-field-' type) key=key property=property document=location}}
{{/each-property}}

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

ember-json-schema-views's People

Contributors

mattwiese-aptible avatar skylar-anderson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ember-json-schema-views's Issues

Refactor dependent properties

Our use case for dependent properties is quite a bit outside the JSON schema draft4 spec. Specifically, the spec will require any dependency whose dependent property exists in the document, regardless of its value. There are ways around this by combining schemas and using anyOf or oneOf. While this approach would work great for the validation of documents, it isn't great for generating UI.

My suggested fix is to extend the dependencies schema to allow specific dependent values. As an example:

Current implementation

"shippingAddress": {
  "type": "object",
  "dependencies": {
    "useAlternateShippingAddress": ["streetAddress", "city", "state"]
  },
  "required": ["useAlternateShippingAddress"],
  "properties": {
    "useAlternateShippingAddress": {
      "type": "boolean"
    },
    "streetAddress": {
      "id": "http://jsonschema.net/address/streetAddress",
      "type": "string"
    },
    "city": {
      "id": "http://jsonschema.net/address/city",
      "type": "string"
    },
    "state": {
      "id": "http://jsonschema.net/address/city",
      "type": "string",
      "enum": ["NY", "IN"]
    }
  }
}

Proposed implementation:

"shippingAddress": {
  "type": "object",
  "dependencies": {
    "streetAddress": [{ "useAlternateShippingAddress": [true] }],
    "city": [{ "useAlternateShippingAddress": [true] }],
    "state": [{ "useAlternateShippingAddress": [true] }]
  },
  "required": ["useAlternateShippingAddress"],
  "properties": {
    "useAlternateShippingAddress": {
      "type": "boolean"
    },
    "streetAddress": {
      "id": "http://jsonschema.net/address/streetAddress",
      "type": "string"
    },
    "city": {
      "id": "http://jsonschema.net/address/city",
      "type": "string"
    },
    "state": {
      "id": "http://jsonschema.net/address/city",
      "type": "string",
      "enum": ["NY", "IN"]
    }
  }
}

As described, an array of possible values is applied for each dependency. Eventually, it would be great to be able to apply a schema instead of just an array of valid values.

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.