Skip to main content

Generate HTML forms and bind hierarchical and tabular data.

Project description

Generate HTML forms and bind hierarchical and tabular data with the help of JSON Schema.

Form-Chen supports master-detail relationships and undo/redo transaction management.

It uses grid-chen to produce Excel-like web-components for tabular (aka table/grid/matrix) data.

Edits on the original object are emitted as standard JSON Patch, which can be directly passed to the back end.

Optionally, object properties can be specified by JSON Pointers to be bound to given HTML-elements.

Form-Chen is written in plain EcmaScript 2017 modules and can be directly imported as such with any modern browser.

Usage

usage

<div class="form-chen">
    <!-- JSON Path to root element -->
    <div id="/person"></div>
    <!-- JSON Path to root vip property -->
    <span style="font-size: x-large" id="/person/vip"></span>
</div>
    import {createFormChen} from "./webcomponentwebcomponent.js"

    const schema = {
        title: 'Person',
        pathPrefix: '/person',
        type: 'object',
        properties: {
            name: {
                title: 'Full Name of Person', type: 'string'
            },
            dateOfBirth: {
                title: 'Date of Birth', type: 'string', format: 'full-date'
            },
            vip: {
                type: 'boolean'
            }
        }
    };

    const data = {
        name: 'Frida Krum',
        dateOfBirth: '2019-01-01T00:00Z',
        vip: true
    };

    createFormChen(schema, data);

Demos

See https://decatur.github.io/form-chen

Read Only

At any level, the schema can be marked readOnly:true|false, the default value being false. The readOnly property is inherited by sub-schemas.

DOM Api and CSS Styling

The form is generated as a flat list of paired elements. The input elements are generated with the document ID corresponding to the JSON Pointer to its value.

Pairs Semantic
<label/> <input> For all scalar fields
<label/> <select> For all scalar fields having an enum type
<label/> <checkbox> For all scalar boolean fields
<label> <grid-chen/> </label> For all grid fields
<label class=error/> For errors

In case a field has a unit, then the label will have a nested <span class=unit/> element.

No direct element style is applied.

Based on this flat list of paired elements, the layout can be tweaked using CSS Column Layout, CSS Grid Layout or CSS Flex Layout, or whatever. See the demos for examples.

JavaScript Api

Please see the source code of the demos or form-chen TypeScript Definitions for the public JavaScript Api.

Development

Form-Chen is written in plain EcmaScript 2017 modules with JSDocs type hinting. There is no overhead related to transpiling or packing. As tool I recommend either vscode or one of the JetBrains IDEs (WebStorm, PyCharm).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

formchen-0.1.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

formchen-0.1.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file formchen-0.1.0.tar.gz.

File metadata

  • Download URL: formchen-0.1.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.6.8 Windows/10

File hashes

Hashes for formchen-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fdd0d18e5838631dfc92186a8e583fd3e4ba55477b306850ce6dab35f1bb44d1
MD5 ef14a72e38a3c2523b6a2a3f5affce9e
BLAKE2b-256 94dee74bfdd6519db44cd3a6f53e8cc2c39b0ba7712506b77c187f9eea115e35

See more details on using hashes here.

File details

Details for the file formchen-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: formchen-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.6.8 Windows/10

File hashes

Hashes for formchen-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10f70985018240e708debacd8b8178d7534eb21ff44b4874d04560ad3350ede5
MD5 374d851244db9e7b361788214425da4a
BLAKE2b-256 f65a4e859755c7eacd0ccc4ab5b28162f0a85d840eabaf426dae87919d967c12

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page