1.12.0 • Published 5 years ago

json-form-custom-element v1.12.0

Weekly downloads
8
License
GNU GENERAL PUBLI...
Repository
github
Last release
5 years ago

json-form-custom-element

https://www.webcomponents.org/element/json-form-custom-element

<json-form
    schema='{"type":"string","title":"Hello","description":"A brief but helpful description of value","maxLength":5}'
    value='"world"'
></json-form>

Install

You can either use unpkg.com CDN

<script src="//unpkg.com/json-form-custom-element"></script>

or as a dependency, in es6

import 'json-form-custom-element'

Installation process uses customElements.define browser API (which supported by current FireFox and Chrome, it may require polyfill in other browsers).

Usage

<json-form schema='{}' value='{}' config='{}'></json-form>

Attributes:

  • schema, strinigified json schema, which may contain some additional ui specifications, see https://json-tools.github.io/json-form/ for example of schema configurations
  • value, strinigified json value
  • config, stringified json object which may contain these properties
    • dense: true | false (boolean) - choose between dense and regular layout
    • textFieldStyle: "outlined" | "filled" (string) - style of text fields
    • name: (string) - name of a form, should be unique on the page, used to generate unique ids of form elements
    • collapseNestedObjects: (boolean) - make nested json forms expandable (collapsed by default)
    • customCss: (string) - custom stylesheet, replaces builtin styling
    • showErrorIcon: (boolean) - whether to show inline error icon when validation fails (default true)

Events:

  • change: CustomEvent with detail { isValid: boolean, value, errors: { [path]: [string] }}

Styles:

  • --nested-object-padding: padding of a nested object, default 0px
  • --expandable-section-padding: padding of an expandable object, default 0 10px
  • --form-background: background of a form, default #fafafa
  • --font-family: font family for form elements, default helvetica, sans-serif
  • --color-active: color of active element, default #27b9cc
  • --color-inactive: color of inactive element, default #8a8a8a
  • --color-invalid: color of invalid element, default #c72227

JSON Schema

A few notes on how json schema interpeted by form generator.

Types

For the sake of simpliticy form generator uses a "type" keyword of JSON Schema in order to identify type of the field. When "type" keyword is an array or types or missing then value edited as json string. Boolean renders toggle, but can be customized to render a checkbox.

Title

Title rendered as label for terminal input fields (leaf nodes of the value), and as h3 headers for objects.

Required

Keyword required of object type used to identify whether to display * near the label. Optional text fields also have button to erase value displayed.

Contribution

Main json-form repository is here: https://github.com/json-tools/json-form please report all bugs there. Issues are disabled in this project.

1.12.0

5 years ago

1.11.0

5 years ago

1.10.0

5 years ago

1.9.0

5 years ago

1.8.3

5 years ago

1.8.2

5 years ago

1.8.1

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.5

6 years ago

1.4.4

6 years ago

1.4.3

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.5

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago