Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:antonreshetov/vue-form-components in…
Browse files Browse the repository at this point in the history
…to dev
  • Loading branch information
antonreshetov committed Apr 15, 2019
2 parents 7ae1d34 + 78e3454 commit cb92c9d
Show file tree
Hide file tree
Showing 25 changed files with 11,465 additions and 16,596 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
node: true
},
'extends': [
'plugin:vue/essential',
'plugin:vue/recommended',
'@vue/standard'
],
rules: {
Expand Down
4 changes: 4 additions & 0 deletions example/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export default {
{
title: 'Form',
path: '/components/form'
},
{
title: 'Form Builder',
path: '/components/form-builder'
}
]
}
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module.exports = {
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
'^.+\\.jsx?$': 'babel-jest'
},
transformIgnorePatterns: [
'/node_modules/'
],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},
Expand Down
16,326 changes: 0 additions & 16,326 deletions package-lock.json

This file was deleted.

34 changes: 26 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,44 @@
"test:unit": "vue-cli-service test:unit"
},
"dependencies": {
"async-validator": "^1.10.0",
"popper.js": "^1.14.4",
"vue": "^2.5.17",
"vee-validate": "^2.2.0",
"vue": "^2.6.0",
"vue-router": "^3.0.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.0.3",
"@vue/cli-plugin-eslint": "^3.0.3",
"@vue/cli-plugin-unit-jest": "^3.0.3",
"@vue/cli-service": "^3.0.3",
"@vue/eslint-config-standard": "^3.0.3",
"@vue/cli-plugin-babel": "^3.5.0",
"@vue/cli-plugin-eslint": "^3.5.0",
"@vue/cli-plugin-unit-jest": "^3.5.0",
"@vue/cli-service": "^3.5.0",
"@vue/eslint-config-standard": "^4.0.0",
"@vue/test-utils": "^1.0.0-beta.20",
"axios": "^0.18.0",
"babel-core": "7.0.0-bridge.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.0.1",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.2.2",
"flush-promises": "^1.0.2",
"highlight.js": "^9.12.0",
"lint-staged": "^8.1.5",
"marked": "^0.5.1",
"node-sass": "^4.9.3",
"sass-loader": "^7.1.0",
"vue-svg-loader": "^0.10.0",
"vue-template-compiler": "^2.5.17"
},
"gitHooks": {
"pre-commit": "lint-staged"
},
"lint-staged": {
"*.js": [
"vue-cli-service lint",
"git add"
],
"*.vue": [
"vue-cli-service lint",
"git add"
]
}
}
18 changes: 16 additions & 2 deletions public/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

`1.1.0` - ADD: Collapse tags props in Select
## `2.0.0`

### BREAKING
- Drop async validation
- Add VeeValidate for form validation

`1.0.0` - First release
### ADD
- Form Builder

## `1.1.0`

### ADD
- Collapse tags props in Select

## `1.0.0`

First release
222 changes: 222 additions & 0 deletions public/docs/form-builder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
# Form builder

Is a schema-based builder to generate form with components and validation

## Basic usage

```example
<template>
<div>
<vue-form-builder
ref="form"
v-model="model"
:schema="schema"
:options="schema.formOptions"
@action="onAction"
></vue-form-builder>
<!-- <pre>{{ model }}</pre> -->
</div>
</template>
<script>
export default {
data () {
return {
model: {
id: 1,
name: 'John Doe',
password: '',
passwordConfirm: '',
skills: [1],
email: 'john.doe@gmail.com',
status: true,
addons: [1, 3],
delivery: 1,
comment: 'Some comment'
},
schema: {
fields: [
{
type: 'input',
inputType: 'input',
label: 'ID',
name: 'input',
model: 'id',
readonly: true,
disabled: true,
validate: {
required: true
}
},
{
type: 'input',
inputType: 'password',
label: 'Password',
name: 'password',
placeholder: 'Type password',
model: 'password',
validate: {
required: true
}
},
{
type: 'input',
inputType: 'password',
label: 'Password confirm',
name: 'passwordConfirm',
placeholder: 'Confirm password',
model: 'passwordConfirm',
validate: {
required: true,
confirmed: 'password'
}
},
{
type: 'select',
label: 'Skills',
model: 'skills',
name: 'skills',
placeholder: 'Select',
options: [
{ label: 'label 1', value: 1 },
{ label: 'label 2', value: 2 },
{ label: 'label 3', value: 3 }
],
validate: {
required: true,
included: [1, 2]
}
},
{
type: 'input',
inputType: 'input',
label: 'Email',
name: 'email',
placeholder: 'Type email',
model: 'email',
validate: {
required: true,
email: true
}
},
{
type: 'checkbox',
label: 'Status',
name: 'status',
checkboxLabel: 'Some text',
model: 'status',
validate: {
required: [true]
}
},
{
type: 'checkbox',
label: 'Addons',
name: 'addons',
model: 'addons',
options: [
{ label: 'label 1', value: 1 },
{ label: 'label 2', value: 2 },
{ label: 'label 3', value: 3 }
],
validate: {
required: true
}
},
{
type: 'radio',
label: 'Delivery',
name: 'delivery',
model: 'delivery',
options: [
{ label: 'label 1', value: 1 },
{ label: 'label 2', value: 2 },
{ label: 'label 3', value: 3 }
],
validate: {
required: true
}
},
{
type: 'input',
inputType: 'textarea',
name: 'comment',
label: 'Comment',
model: 'comment',
validate: {
required: true,
min: 10
}
},
{
type: 'actions',
buttons: [
{
type: 'cancel',
buttonType: 'default',
buttonLabel: 'Cancel'
},
{
type: 'submit',
buttonType: 'success',
buttonLabel: 'Submit'
}
]
}
],
formOptions: {
labelPosition: 'right',
labelWidth: '120px'
}
}
}
},
methods: {
async onAction (e) {
if (e.type === 'submit') {
const res = await this.$refs.form.$validator.validate()
if (res) alert('Form is valid')
}
}
}
}
</script>
```

## Attributes

| Attributes | Description | Type | Accepted values | Default |
| ---------- | -------------------------------------------- | -------- | --------------- | ------- |
| `model` | Model for form fields (components `v-model`) | `Object` | - | - |
| `schema` | Schema to generate form | `Object` | - | - |
| `options` | Options for <a href="#/components/form">Form</a> component: label position & label width | `Object` | - | - |

## Schema

| Property | Description | Type | Accepted values |
| --------------------- | ----------------------------------------------------------- | ------------------ | ------------------------------------------------------- |
| `type` | Type of field | `String` | input, select, checkbox, radio, actions |
| `inputType` | Type of input | `String` | text, number, textarea, password and border<sup>1</sup> |
| `buttons` | Form action buttons. Available if type is `actions` | `Array` | |
| `buttons.type` | Type of button. Also event emitter type for `@action` | `String` | submit, cancel |
| `buttons.buttonType` | Type of <a href="#/components/button">Button</a> component | `String` | primary, success, warning, danger |
| `buttons.buttonLabel` | Label for button | `String` | |
| `name` | Field detection to start validation and error messages | `Object` | |
| `label` | Label of the form item | `String` | |
| `model` | Name of property in the model | `String` | |
| `disabled` | Disable the field | `Boolean` | |
| `readonly` | Same as `readonly` in native input | `Boolean` | |
| `placeholder` | Placeholder of value | `Boolean` | |
| `options` | Options for list components, like Select or Checkbox | `Array` | |
| `options.label` | Label of option | `String` | |
| `options.value` | Value of option | `String`, `Number` | |
| `validate` | VeeValidate <a href="https://baianat.github.io/vee-validate/guide/rules.html?ref=vfc">rules</a> | `Object` | |

- <sup>1</sup> `border` is available only if `type` is checkbox or radio.

## Form events

| Name | Description | Payload |
| -------- | --------------------------------- | --------------------- |
| `action` | Triggers when clicked action button | Type of action button |
Loading

0 comments on commit cb92c9d

Please sign in to comment.