Skip to main content

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 gridchen 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.

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

Installation

Either

Note: cdn.jsdelivr.net currently does not support bare module specifiers.

Usage

This is a basic form which runs standalone or can be loaded from https://decatur.github.io/formchen/usage.html. usage

<!DOCTYPE html>
<div class="form-chen">
    <div id="/person"></div>
    <span style="font-size: x-large" id="/person/vip"></span>
</div>
<script type="module">
    import {createFormChen} from "https://decatur.github.io/formchen/formchen/webcomponent.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);
</script>

Demos

See https://decatur.github.io/formchen

Hosting Form-Chen

Deploy both formchen and gridchen directories from the respective git repositories. formchen depends on gridchen to be at the bare URL gridchen, i.e. import "gridchen/webcomponent.js" So be sure you bundle or inplace your imports.

NPM Install

⚠ Currently formchen is not registered with npmjs!

Python PyPI Install

Using Python you can install the formchen package. A Python routing example can be found in the provided dev server.

Note on module resolving

The old way of module resolution is via bare import specifiers such as import "gridchen/webcomponent.js". Note the missing slash at the beginning. This is usually handled by bundlers, which replace the bare import specifier with a relative path to the routed module location. As we do not want to rely on any bundler, and because currently there is no Web browser standard for module resolution of bare import specifiers, we opted for the relative URL approach.

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 formchen TypeScript Definitions for the public JavaScript Api.

Contribute

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 JetBrains IDEs (WebStorm, PyCharm).

Dev Server

There is a FastAPI-based dev server in the dev_server directory.

Unit Testing

After starting the dev server, navigate to http://localhost:8000/gridchen/testing/suiterunner.html?testpath=/formchen/tests/

Project Website

Formchen can be deployed to a static web server. We use Github Pages and serve from /docs of the master branch. The /docs folder is generated from project root by running

python build.py

This will substitute the bare import specifier gridchen/ with https://decatur.github.io/gridchen/gridchen/.

Steps:

  1. python build.py
  2. Test web site locally by opening ./docs/index.html (PyCharm: Open in browser) and navigating the site.
  3. git push
  4. Test web site on Formchen Github Pages

Python Package

vi setup.py
git commit . -m'bumped version'
git tag x.y.z
python setup.py sdist bdist_wheel

Python Publish

python -m twine upload dist/*

Publish as npm Package

Bump version in fromchen/package.json and git tag.

cd fromchen & npm publish

Release files for formchen 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for formchen 0.1.6
File Size Uploaded
formchen-0.1.6.tar.gz 16.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for formchen 0.1.6
File Interpreter ABI Platform
formchen-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 35.1 kB

Release files / formchen-0.1.6.tar.gz

Download URL formchen-0.1.6.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b4b3b31b1da4c5e5220d1dfc2b2780de11611b1a21493f925c3a3a1aa0944c55
BLAKE2b-256 checksum
How to use checksums
36707c15e94956ea459619c954075e2eb22069dfb71fb9cae91f49d75a96b08d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

Release files / formchen-0.1.6-py3-none-any.whl

Download URL formchen-0.1.6-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2cc6e7a1213929c927734802a1bc86b42415bc2805b56d21059c8274747f2e41
BLAKE2b-256 checksum
How to use checksums
3858cb39902f80c862ddf5d3fd4963dfbcdf6217dbbf9ecab3c3f5615f47a331
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

0.1.3

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page