Skip to content

Commit 4940592

Browse files
committed
✏️ docs
1 parent 932a20d commit 4940592

File tree

4 files changed

+170
-0
lines changed

4 files changed

+170
-0
lines changed

docs/fields/README.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Available fields
2+
3+
## Built-in fields
4+
5+
For this fields there is no need 3rd party libraries
6+
7+
- [`text`](text.md) - Simple text input field
8+
- `email` - E-mail address input field
9+
- `password` - Password input field
10+
- `number` - Number input field
11+
- `textArea` - Text area field
12+
- `checkbox` - Checkbox for boolean values
13+
- `select` - Select list
14+
- `color` - Color picker (built-in HTML5 control)
15+
- `checklist` - Checkbox list to select multiple values
16+
- `range` - Range slider (built-in HTML5 control)
17+
- `image` - Image select field (URL or upload in base64 string)
18+
- `label` - Static text (e.g. timestamp, creation time...etc)
19+
20+
## Optional fields
21+
22+
For this fields needs 3rd party libraries
23+
24+
- `selectEx` - select list with the bootstrap-select component
25+
- `dateTime` - datetime picker with bootstrap-datetimepicker component
26+
- `masked` - Masked text input field with maskedinput component
27+
- `slider` - pretty range slider with ion.rangeSlider component
28+
- `spectrum` - Color picker with "The No Hassle" Spectrum jQuery Colorpicker component
29+
30+
## Common properties of field
31+
32+
Property | Type | Description
33+
--------------- | ------------- | -----------
34+
type | `String` | Type of field
35+
label | `String` | Label of field
36+
model | `String` | Name of property in the model
37+
featured | `boolean` | is it a featured (bold) field?
38+
disabled | `boolean` | if true, disable this field
39+
required | `boolean` | if true, must be fill this field
40+
default | any | Default value of the field (for create a new model)
41+
validator | `Function` or `Array` | Validator for value. It can be array of functions too.
42+
onChanged | `Function` | Event if this field value is changed. `onChanged(model, newVal, oldVal, field) { ... }`
43+
onValidated | `Function` | Event if validation executed. `onValidated(model, errors, field) { ... }`
44+
45+
## Example
46+
47+
```js
48+
{
49+
type: "text",
50+
label: "Name",
51+
model: "name",
52+
readonly: false,
53+
featured: true,
54+
disabled: false,
55+
required: true,
56+
default: "Anonymous",
57+
validator: validators.string,
58+
59+
onChanged(model, newVal, oldVal, field) {
60+
console.log(`Model's name changed from ${oldVal} to ${newVal}. Model:`, model);
61+
},
62+
63+
onValidated(model, errors, field) {
64+
if (errors.length > 0)
65+
console.warn("Validation error in Name field! Errors:", errors);
66+
}
67+
}
68+
```

docs/fields/text.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# `text` field
2+
3+
## Special properties of field
4+
5+
Property | Type | Description
6+
--------------- | ------------- | -----------
7+
readonly | `boolean` | If true, the input field is read-only
8+
placeholder | `String` | Placeholder text for input field
9+
min | `Number` | Minimum length of text (need `validators.string`)
10+
max | `Number` | Maximum length of text (need `validators.string`)
11+
12+
## Usage
13+
14+
```js
15+
{
16+
type: "text",
17+
label: "Name",
18+
model: "name",
19+
min: 3,
20+
max: 50,
21+
required: true,
22+
placeholder: "User's full name",
23+
24+
onChanged(model, newVal, oldVal, field) {
25+
console.log(`Model's name changed from ${oldVal} to ${newVal}. Model:`, model);
26+
},
27+
28+
onValidated(model, errors, field) {
29+
if (errors.length > 0)
30+
console.warn("Validation error in Name field! Errors:", errors);
31+
}
32+
}
33+
```

docs/main.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# VueFormGenerator component
2+
3+
## Component properties
4+
5+
Property | Type | Description
6+
-------- | ---- | -----------
7+
[schema](schema.md)| `Object` | Schema object with fields
8+
[options](options.md) | `Object` | form options
9+
model | `Object` | Model/target object
10+
multiple | `boolean` | Is it a multiple merged model? We only show `multi: true` fields
11+
isNewModel | `boolean` | If model is new/empty, we won't validate after it load
12+
13+
## Usage
14+
```html
15+
<template>
16+
<div class="panel-body">
17+
<vue-form-generator :schema="schema" :model="model" :options="formOptions"></vue-form-generator>
18+
</div>
19+
</template>
20+
21+
<script>
22+
import VueFormGenerator from "vue-form-generator";
23+
24+
export default {
25+
...
26+
components: {
27+
VueFormGenerator: VueFormGenerator.component
28+
},
29+
30+
data: {
31+
schema: { ... },
32+
model:
33+
id: 1,
34+
name: "John Doe",
35+
password: "J0hnD03!x4",
36+
skills: ["Javascript", "VueJS"],
37+
38+
status: true
39+
},
40+
formOptions: {
41+
validateAfterLoad: true,
42+
validateAfterChanged: true
43+
}
44+
}
45+
...
46+
</script>
47+
```

docs/schema.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Schema
2+
The schema contains the fields of the form
3+
4+
## Sample
5+
```js
6+
{
7+
fields: [
8+
{
9+
type: "text",
10+
label: "Name",
11+
model: "name"
12+
},
13+
{
14+
type: "number",
15+
label: "Age",
16+
model: "age"
17+
}
18+
]
19+
}
20+
```
21+
22+
[Available field types](fields/README.md)

0 commit comments

Comments
 (0)