# form-generator-vue

> Create beautiful forms using any component library for vue. ## Features * reactive schema based form. * compatible with third party component libraries like vuetify, element etc and custom components. * customizable form layout. ## [Demo](https://divijbha

Latest version **2.0.1** (published 2021-03-07) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install form-generator-vue
pnpm add form-generator-vue
yarn add form-generator-vue
bun add form-generator-vue
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2021-03-07 |
| First published | 2020-06-24 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 83.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | divij |
| Keywords | vue, nuxt, form, form-schema, schema-form-generator, generator, form-generator, form-builder, vue-form, nuxt-form |

## Links

- npm: https://www.npmjs.com/package/form-generator-vue
- npm.io page: https://npm.io/package/form-generator-vue

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2021-03-07
- 2.0.0 — 2021-03-05
- 1.1.7 — 2020-12-15
- 1.1.6 — 2020-12-11
- 1.1.5 — 2020-12-10
- 1.1.4 — 2020-11-24
- 1.1.3 — 2020-11-16
- 1.1.2 — 2020-10-06
- 1.1.1 — 2020-10-03
- 1.1.0 — 2020-10-03
- 1.0.9 — 2020-09-17
- 1.0.8 — 2020-08-18
- 1.0.7 — 2020-08-16
- 1.0.6 — 2020-08-12
- 1.0.5 — 2020-08-08
- … 5 more at https://npm.io/package/form-generator-vue/versions

## README

Create beautiful forms using any component library for vue.
## Features
* reactive schema based form.
* compatible with third party component libraries like vuetify, element etc and custom components.
* customizable form layout.
## [Demo](https://divijbhardwaj.github.io/form-generator-vue-demo/)
## Installation
```
npm install form-generator-vue
```
## How to use
```vue
<template>
    <form-generator-vue 
        v-model="fields"
        :components="formComponents"
        :schema="schema"
        :on-submit="handleSubmit"
    >
        <template v-slot:footer>
            <button type="submit">submit</button>
        </template>
    </form-generator-vue>
</template>

<script>
import FormGeneratorVue from 'form-generator-vue';
export default {
    data() {
        return {
            fields: {}
        }
    },
    components: {
        FormGeneratorVue
    },
    computed: {
        formComponents: () => [
            {   
                name: 'v-text-field', //should be a globally registered component.
                type: ['text', 'password', 'email', 'number'],
                errorProp: 'errorMessages'
            },
            {   
                name: 'v-radio-group',
                type: ['radio']
            }
        ],
        schema() {
          return {
            fields: [
              {
                model: 'email',
                type: 'email'
              },
              {
                model: 'mobile',
                type: 'number'
              },
              {
                model: 'password',
                type: 'password'
              }
            ]
          }
        }
    },
    methods: {
        async handleSubmit() {
            // await network call ---------;
            console.log('form submitted', this.fields)
        }
    }
}
</script>
```
## Props
|props|type|description|
|----|---|----|
| schema | obj | json schema to create form |
| components | obj | component map to render component for specific type of field |
| onSubmit | async/sync function | submit success function |
| onSubmitFail | async/sync function | submit fail function.|
| disabled | Bool | toggle disable all fields |
| activeValidation | bool | toggle validation on input for all fields. Default is **false** |
| activeValidationDelay | Number | debounced validation for all fields|
| logs | bool | toggle validation and submit logs |
| classes | obj | To add classes to all the rows and columns inside form body |

## field schema Options
| options | type | default | purpose |
| ------ | ------ | ------ | ----- |
| model | String |  | v-model with component.|
| type | String | 'text' | Input type. Component for it is loaded from `components`. |
| props| obj | {} | Component props |
| hide | bool/() => bool | false | show/hide field. Not required when hidden |
| v-on | obj | {} | Assigned to component `v-on`. |
|validator | () => //return error data | | function returning error data(string, array etc) on validation fail. |
| component | String |  | for using any component |
| errorProp | String | 'errorMessages' | name of error prop consumed by component to show error |
| activeValidation | Boolean | false | toggle validation on input |
| activeValidationDelay | Number | 0 | debounced validation |

## Layout
Row is a div containing column div containing the component. A row can have multiple cols. Nested rows are not supported.
```js
fields: [   // 1 row 1 column -------
            {
                model: 'name',
                type: 'text'
            },
            // 1 row 1 column -------
            {
                model: 'email',
                type: 'email'
            },
            
            // 1 row 2 columns -------   
            [
                {
                    model: 'mobile',
                    type: 'number'
                },
                {
                    model: 'password',
                    type: 'password'
                }  
            ]
        ]
```

## Slots
* header
* before-row
* after-row`
* before-col
* after-col
* `<model>` **(for using the component slot)**
* before-`<model>`
* after-`<model>`
* footer

slot prop `model` is passed to all slots except for slots header and footer.
## classes used
* form - **"fgv-form"**
    * header - **"fgv-form__header"**
    * body - **"fgv-form__body"**
        * row - **"fgv-form__body__row"**
            * col - **"fgv-form__body__row__col `<model>`"**
    * footer - **"fgv-form__footer"**

## Contributors
This project exists thanks to all the people who contribute. [Contribute](https://github.com/divijhardwaj/form-generator-vue).

* [Carlos Noguera](https://github.com/kaysersoze)

## [Changelog](https://github.com/divijbhardwaj/form-generator-vue/blob/master/changelog.md)

---
_Source: https://npm.io/package/form-generator-vue · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
