Skip to content

Commit

Permalink
docs: update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
neferin12 committed Aug 15, 2023
1 parent fcacffc commit fe7e364
Show file tree
Hide file tree
Showing 32 changed files with 611 additions and 116 deletions.
143 changes: 108 additions & 35 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# @educorvi/vue-json-form

[![GitHub release (latest by date)](https://img.shields.io/github/v/release/educorvi/vue_json_form)](/~https://github.com/educorvi/vue_json_form/releases/latest)
[![npm](https://img.shields.io/npm/v/@educorvi/vue-json-form)](https://www.npmjs.com/package/@educorvi/vue-json-form)
[![End2End Tests](/~https://github.com/educorvi/vue_json_form/actions/workflows/cypress.yml/badge.svg)](/~https://github.com/educorvi/vue_json_form/actions/workflows/cypress.yml)
[![Browserstack Tests](/~https://github.com/educorvi/vue_json_form/actions/workflows/browserstack.yml/badge.svg)](/~https://github.com/educorvi/vue_json_form/actions/workflows/browserstack.yml)
[![GitHub issues](https://img.shields.io/github/issues/educorvi/vue_json_form)](/~https://github.com/educorvi/vue_json_form/issues)

#### Automaticly generates form from json schema and json ui schema.

- [Documentation](https://educorvi.github.io/vue_json_form/)
- [Demo](https://educorvi.github.io/vue_json_form/demo/)

## Usage
Install with `npm install @educorvi/vue-json-form`. This Component needs [Bootstrap-Vue](https://bootstrap-vue.org/) installed to work. If you want to use the wizard, you also have to MdStepper and MdButton from [Vue Material](https://vuematerial.io/).

Install with `npm install @educorvi/vue-json-form`. This Component needs [Bootstrap-Vue](https://bootstrap-vue.org/)
installed to work. If you want to use the wizard, you also have to MdStepper and MdButton
from [Vue Material](https://vuematerial.io/).
Your `main.js` file should look something like this:

``` js
Expand Down Expand Up @@ -40,7 +46,8 @@ new Vue({
}).$mount('#app')
```

### Use in VueJS-Component
### Use in VueJS-Component

``` vue
<template>
<json-form :json="form" :on-submit="mySubmitMethod"/>
Expand All @@ -65,6 +72,7 @@ export default {
```

### Props

| Name | Description | Type | Required | Default |
|-------------------|------------------------------------------------------------------------------------------|-------------------|----------|---------|
| json | The form's JSON Schema | `Object` | `true` | - |
Expand All @@ -73,9 +81,12 @@ export default {
| disableValidation | Disables the validation of json-schema and ui-schema | `Boolean` | `false` | false |

### Other Options
If you want to change the default submit button or add more buttons or other components to the bottom of the form, you can do so by overriding the default button and put your components in the default slot.

If you want to change the default submit button or add more buttons or other components to the bottom of the form, you
can do so by overriding the default button and put your components in the default slot.
When doing that, it is important, that the button, that is supposed to submit the form, has `type=submit`.
Example:

``` vue
<template>
<json-form :json="form">
Expand All @@ -98,103 +109,165 @@ export default {
```

### Use as a Web Component

Can be used as a webcomponent. The form data will be posted to a given endpoint. Example:

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="https://unpkg.com/@educorvi/vue-json-form/dist/webcomponent/dist.css">
<link rel="stylesheet" href="https://unpkg.com/@educorvi/vue-json-form@^2/dist/webcomponent/dist.css">
</head>
<body>
<!-- use_x_www_form_urlencoded: Send data urlencoded instead of json-->
<!-- post_url: Url to post the data to-->
<!-- json: Your JSON Schema -->
<!-- ui: Your UI Schema -->
<vue-json-form
use_x_www_form_urlencoded="false"
post_url='https://YourPostURL.com'
json='{...}'
ui='{...}'
></vue-json-form>


<script src="https://unpkg.com/@educorvi/vue-json-form/dist/webcomponent/dist.umd.min.js"></script>
<script src="https://unpkg.com/@educorvi/vue-json-form/dist/webcomponent@^2/dist.umd.min.js"></script>
</body>
</html>
```

A working example can be found in the file `webcomponent_example.html`.

When using the webcomponent you need to specify at least one submit button in the ui schema, so the form can be properly
submitted.
Here an example with multiple buttons:

```json
{
"type": "Buttongroup",
"buttons": [
{
"type": "Button",
"buttonType": "submit",
"nativeSubmitSettings": {
"formaction": "http://localhost:6969/post1",
"formmethod": "post",
"formenctype": "multipart/form-data"
},
"text": "submit form-data"
},
{
"type": "Button",
"buttonType": "submit",
"nativeSubmitSettings": {
"formaction": "http://localhost:6969/post1",
"formmethod": "post",
"formenctype": "application/x-www-form-urlencoded"
},
"text": "submit x-www-form-urlencoded"
},
{
"type": "Button",
"buttonType": "reset",
"text": "Reset form"
}
]
}
```

### About the Schemas
The form fields themselve are defined in the JSON-Schema. In the UI-Schema, the layout of the form is defined. Fields are inserted into the form by creating a `Control` in the UI-Schema and referring to the field in the JSON-Schema with a json pointer.

The form fields themselve are defined in the JSON-Schema. In the UI-Schema, the layout of the form is defined. Fields
are inserted into the form by creating a `Control` in the UI-Schema and referring to the field in the JSON-Schema with a
json pointer.
[Examples](/~https://github.com/educorvi/vue_json_form/tree/master/src/exampleSchemas)

#### JSON-Schema

The JSON-Schema must be a valid JSON-Schema.
More details on the json-schema can be found [here](https://json-schema.org/).

#### UI-Schema
The UI-schema must conform to [https://educorvi.github.io/vue_json_form/schemas/ui.schema.json](https://educorvi.github.io/vue_json_form/schemas/ui.schema.json).
Your root object must be a [layout](https://educorvi.github.io/vue_json_form/schemaDoc/#/layout) or a [wizard](https://educorvi.github.io/vue_json_form/schemaDoc/#/wizard).
A layout can be of type `VerticalLayout`, `HorizontalLayout` or `Group` and needs to have an array of [elements](https://educorvi.github.io/vue_json_form/schemaDoc/#/layout-properties-elements-layoutelement).

A wizard needs to have a pages property, which is an array. Each arrayitem needs to hav a title and a content array.

The formfields are represented by elements with [Control](https://educorvi.github.io/vue_json_form/schemaDoc/#/control) objects. They must have a `scope` property, which has the form of a json-pointer and points to the element in the json-schema, that you want to display here.
It can be customized with the [options](https://educorvi.github.io/vue_json_form/schemaDoc/#/control-properties-options) property.
If your control object is for a string, you can set the format of the string with the [format](https://educorvi.github.io/vue_json_form/schemaDoc/#/control#format) property.
The UI-schema must conform
to [https://educorvi.github.io/vue_json_form/schemas/ui.schema.json](https://educorvi.github.io/vue_json_form/schemas/ui.schema.json).
Your root object must be a [layout](https://educorvi.github.io/vue_json_form/schemaDoc/#/layout) or
a [wizard](https://educorvi.github.io/vue_json_form/schemaDoc/#/wizard).
A layout can be of type `VerticalLayout`, `HorizontalLayout` or `Group` and needs to have an array
of [elements](https://educorvi.github.io/vue_json_form/schemaDoc/#/layout-properties-elements-layoutelement).

Other possible elements are a [HTML renderer](https://educorvi.github.io/vue_json_form/schemaDoc/#/html) and a [divider](https://educorvi.github.io/vue_json_form/schemaDoc/#/divider).

For all types (except wizard pages) it is possible, to define conditional rendering with the [showOn](https://educorvi.github.io/vue_json_form/schemaDoc/#/control-properties-showon-property) property.
Use `scope` to specify a json pointer to the field the reference value should be compared against, `referenceValue` to specify the value and `type` to specify, what kind of comparison should be used. Possible are:

| Value | Explanation |
| :------------------- | ----------- |
| `"EQUALS"` | If the field value and the referenceValue are equal |
| `"NOT_EQUALS"` | If the field value and the referenceValue are not equal |
| `"GREATER"` | If the field value is greater then the referenceValue |
| `"GREATER_OR_EQUAL"` | If the field value is greater or equal then the referenceValue |
| `"SMALLER_OR_EQUAL"` | If the field value is smaller or equal then the referenceValue |
| `"SMALLER"` | If the field value is smaller then the referenceValue |
| `"LONGER"` | Used for strings. If the length of the input in the field specified by `scope` is bigger than the value in `referenceValue`, field will be rendered |

#### Examples
For examples have a look in [this folder](/~https://github.com/educorvi/vue_json_form/tree/master/src/exampleSchemas). To see these examples rendered, open the [demo](https://educorvi.github.io/vue_json_form/demo/) and select the example you want to see from the dropdown menu.
A wizard needs to have a pages property, which is an array. Each arrayitem needs to hav a title and a content array.

The formfields are represented by elements with [Control](https://educorvi.github.io/vue_json_form/schemaDoc/#/control)
objects. They must have a `scope` property, which has the form of a json-pointer and points to the element in the
json-schema, that you want to display here.
It can be customized with the [options](https://educorvi.github.io/vue_json_form/schemaDoc/#/control-properties-options)
property.
If your control object is for a string, you can set the format of the string with
the [format](https://educorvi.github.io/vue_json_form/schemaDoc/#/control#format) property.

Other possible elements are a [HTML renderer](https://educorvi.github.io/vue_json_form/schemaDoc/#/html) and
a [divider](https://educorvi.github.io/vue_json_form/schemaDoc/#/divider).

For all types (except wizard pages) it is possible, to define conditional rendering with
the [showOn](https://educorvi.github.io/vue_json_form/schemaDoc/#/control-properties-showon-property) property.
Use `scope` to specify a json pointer to the field the reference value should be compared against, `referenceValue` to
specify the value and `type` to specify, what kind of comparison should be used. Possible are:

| Value | Explanation |
|:---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| `"EQUALS"` | If the field value and the referenceValue are equal |
| `"NOT_EQUALS"` | If the field value and the referenceValue are not equal |
| `"GREATER"` | If the field value is greater then the referenceValue |
| `"GREATER_OR_EQUAL"` | If the field value is greater or equal then the referenceValue |
| `"SMALLER_OR_EQUAL"` | If the field value is smaller or equal then the referenceValue |
| `"SMALLER"` | If the field value is smaller then the referenceValue |
| `"LONGER"` | Used for strings. If the length of the input in the field specified by `scope` is bigger than the value in `referenceValue`, field will be rendered |

#### Examples

For examples have a look in [this folder](/~https://github.com/educorvi/vue_json_form/tree/master/src/exampleSchemas). To
see these examples rendered, open the [demo](https://educorvi.github.io/vue_json_form/demo/) and select the example you
want to see from the dropdown menu.

## Development

## Project setup

```
npm install
```

### Compiles and hot-reloads for development

```
npm run serve
```

### Lints and fixes files

```
npm run lint
```

### Compiles and minifies for production

```
npm run build
```

### Zips the build-folders

```
npm run zip
```

### Generates the documentation

```
npm run doc
```

### Removes all build-folders

```
npm run clean
```
12 changes: 12 additions & 0 deletions docs/components/ButtonGroup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ButtonGroup

## MixIns

<!-- @vuese:ButtonGroup:mixIns:start -->
|MixIn|
|---|
|layoutMixin|

<!-- @vuese:ButtonGroup:mixIns:end -->


14 changes: 12 additions & 2 deletions docs/components/FormRoot.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ This is the Root Component and the interface to the "outside". Generates UI if n
<!-- @vuese:FormRoot:props:start -->
|Name|Description|Type|Required|Default|
|---|---|---|---|---|
|disableValidation|Disables the validation of json-schema and ui-schema|`Boolean`|`false`|false|
|onSubmit|Method that is called, when the Form is submitted. Passes the formdata as first Argument|`Function`|`true`|-|
|disableValidation|Disables the validation of json-schema and ui-schema *|`Boolean`|`false`|false|
|onSubmit|Method that is called, when the Form is submitted. Passes the formdata as first Argument *|`Function`|`true`|-|

<!-- @vuese:FormRoot:props:end -->


## Events

<!-- @vuese:FormRoot:events:start -->
|Event Name|Description|Parameters|
|---|---|---|
|changedData|-|-|

<!-- @vuese:FormRoot:events:end -->


## Slots

<!-- @vuese:FormRoot:slots:start -->
Expand Down
2 changes: 0 additions & 2 deletions docs/components/vue_json_form.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
|json|-||`true`|-|
|ui|-||`false`|-|
|disable_validation|-||`false`|false|
|post_url|-||`true`|-|
|use_x_www_form_urlencoded|-|`String`|`false`|false|

<!-- @vuese:vue_json_form:props:end -->

Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit fe7e364

Please sign in to comment.