Library for converting JsonSchema to Form in field validation (for JS)
Vanilla JS
npm i js-json-schema-form
save locally the files from the /lib-to-connect
// reset pinia errors and library vue@3.3.2 (dev)
<script src="lib-to-connect/common.js"></script>
// copy /dist/schema-form.umd.js
<script src="lib-to-connect/schema-form.umd.js"></script>
// styles
<link rel="stylesheet" href="lib-to-connect/style.css">
import SchemaForm from "~/vue3-json-schema-form/dist/schema-form.es.js";
import "~/vue3-json-schema-form/dist/style.css";
const app = document.getElementById("app");
const json = {
"title": "My Json Schema",
"type": "object",
"properties": { "name": { "title": "Имя", "type": "string" } }
};
const formData = { name: "Default Name" };
const props = { schema: json, formData }
SchemaForm;
window.createSchemaForm(app, props);
const app = document.getElementById("app");
const json = {
"title": "My Json Schema",
"type": "object",
"properties": { "name": { "title": "Имя", "type": "string" } }
};
const formData = { name: "Default Name" };
const props = { schema: json, formData }
window.createSchemaForm(app, props);
properties
- An Object with entity fields of the form
-
type
- field value type ("object" or "array" or "string" or "boolean" or "number") -
title
- the output title of the field/node -
description
- the output description of the field/node -
default
- default value -
properties
- only for type="object". This is an object with the same fields as the parent: type, title, properties, items, etc. -
items
- only for type="array", This is an object describing an element of the form array, which has the same fields as the parent: type, title, properties, items, etc. -
validation
- validation field/node:-
required
- Boolean. Is it necessary to fill in field/node -
minimum
/maximum
- limiting the value for numbers -
minlength
/maxlength
- limitation of the allowed number of characters -
hardValue
- fixed mandatory value
-
-
ui
:-
inputType
:- all built-in input types (view here)
- "select"
- "textarea"
-
draggable
- Boolean. Only for inputType="file" - Drag and Drop -
autofocus
- Boolean -
placeholder
- String -
description
- String. Description of the input under the heading -
mask
- input mask ({ mask: "+7(000)000-00-00", lazy: true }) (use vue-imask library)
-
-
customErrors
- Object, in which the keys are the type of error from the validation field, and the value of the field is the text of the custom error -
enum
- Array with a list of possible values (for types "radio", "checkbox", "select")-
["val-1"]
- a one-dimensional array with values. Then the value and the label of the element will be the same -
[{ caption: "one", value: 1, disabled: true }]
- multidimensional array, where caption, value are specified specifically
-
-
grid
- Object - custom item position in the grid-
column
(optional parameter) - Number - occupied column (on all screen resolutions) -
row
(optional parameter) - Number - occupied row (on all screen resolutions) -
media
(optional parameter) - Object of type{ "768": { column: 1, row: 2 } }
(the key is the width of the screen above which it will be applied value (768+)). media permissions can be as many as you want. Has a higher priority than grid.column or grid.row
-
Notes
- What you need to get radio, checkbox, select:
- for the radio list, it is necessary that the node has the field
enum: []
, and thetype
isstring || number || boolean
(if there is the default field, then, of the corresponding type"default": "foo"
) - for the list of checkboxes it is necessary that the node has the field
enum: []
, and thetype
isarray
(if there is the default field, then, of the corresponding type"default": ["foo", "bar"]
) - for the list of options select-a it is necessary that the node has the field
enum: []
and the field"ui":{"inputType":"select"}
. If itstype
isarray
, then it is a multiple-choice selector, iftype
with the valuestring||number|| boolean
, then it is a regular select - if you forget to specify the
enum
field, it will be a completely different type of node
- Toggle
- for a standard toggler, you only need to specify
"type": "boolean"
("default": true/false
)