JSON Form
A form generated from a JSON Schema, laid out by the schema, a UI schema or your own markup.
c2-json-form turns a JSON Schema into a form. The schema describes the data and how it is
validated; the form picks a control for each property from its type, format and enum: a text field, a number input,
a checkbox, a radio group (five options or fewer) or a select, a date or time input, a tag input for a list of strings, a
checkbox group for a list of choices, a card for an object and a repeatable group for a list of objects. Labels come from
title, hints from description, the required marker from required.
How the form is laid out is decided in three layers, each optional:
- Nothing: one field per property, in schema order.
ui-schema: a layout tree in the JSON Forms shape.VerticalLayout,HorizontalLayout,GridLayout(options.columns,options.spanon a child),Group(options.collapsible),Categorization(tabs, oroptions.variant: "stepper") andLabelholdControls, each pointing at the data with ascope(#/properties/billing/properties/zip, or the shorthandbilling.zip). Aruleshows, hides, enables or disables any element from the data,options.widgetpicks another control (textarea,slider,switch,select,radio…), and{ "type": "Control", "scope": "*" }stands for every field not placed elsewhere.- Your own markup: put
c2-json-fieldelements, with any HTML and CSS around them, inside the form. They replace the generated layout; each renders the field itsscopenames.
A field shows its error once its edit is committed; reportValidity() or a submit attempt shows them all and focuses the
first, opening its tab or step. Fields a rule hides do not block the form. Inside a <form>, the element submits its
value as JSON under name and resets with the form; it fires input and change, so v-model and Angular forms bind
value. The built-in validator covers the keywords a form needs without generating code; set validator to use
another, such as Ajv through fromAjvErrors. A new kind of control is a renderer: registerRenderer({ name, tester, render }), the highest tester rank winning.
Import
import '@c2n/components/json-form'