# aca-form-generator

> You can find a succint storybook detailing main components props and events : https://aca-form-generator.netlify.com/storybook/

Latest version **1.1.11** (published 2026-11-20) · 0 weekly downloads

## Install

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

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.1.11 |
| Published | 2026-11-20 |
| First published | 2019-11-25 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 639.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | aca-npm |

## Links

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

## Dependencies (4)

- [core-js](https://npm.io/package/core-js.md) ^3.3.2
- [vue-client-only](https://npm.io/package/vue-client-only.md) ^2.0.0
- [load-google-maps-api](https://npm.io/package/load-google-maps-api.md) ^2.0.2
- [@googlemaps/js-api-loader](https://npm.io/package/@googlemaps/js-api-loader.md) ^1.16.10

## Recent versions

- 1.1.11 (latest) — 2026-11-20
- 1.0.38-beta.0 (beta) — 2022-12-02
- 1.1.10 — 2026-07-02
- 1.1.9 — 2026-06-30
- 1.1.8 — 2026-06-30
- 1.1.7 — 2026-06-30
- 1.1.6 — 2026-06-30
- 1.1.5 — 2026-06-30
- 1.1.4 — 2026-02-19
- 1.1.3 — 2026-01-19
- 1.1.2 — 2025-10-20
- 1.1.1 — 2025-09-23
- 1.1.0 — 2025-09-23
- 1.0.82 — 2025-09-23
- 1.0.81 — 2025-09-22
- … 150 more at https://npm.io/package/aca-form-generator/versions

## README

# aca-form-generator

You can find a succint storybook detailing main components props and events :   
https://aca-form-generator.netlify.com/storybook/  

## FormGenerator

### What is it 
`FormGenerator` is a component used to display a form, without styling.

### What it does
It takes a JSON object describing the form and data.
It handles user inputs.
It returns validation errors.

### What it doesn't do
It doesn't handle sending to the form to any backend.
It doesn't handle step navigation.


### Installation 
`npm install aca-form-generator`  

### Usage 
```js
import { FormGenerator } from 'aca-form-generator'
```

```vue
<script>
export default {
    components: {
        FormGenerator,
    },

    data() {
        return {
            errors: {},
            visibleErrors: {},
            schema: {},
            model: {},
        }
    }
}
</script>
<template>
    <FormGenerator
        :schema="schema"
        :model="model"
        :errors="errors"
        :visibleErrors="visibleErrors"
        @fieldChange="({ field, value }) => this.model = Object.assign({}, this.model, { [field.model]: value })"
        @errorsChange="({ errors }) => (this.errors = errors)"
    >
    </FormGenerator>
</template>

```


### Props 
**schema** : *required*  
Literal object describing the form.
```js
{
    fields: [
        {
            type: 'input',
            model: 'username'
        }, 
        // ...
    ]
}
```
You can find more example of common fields in this file :  
https://github.com/Acadomia/aca-form-generator/blob/master/src/stepsSkeletonExample.js

**model**  
Literal object representing the data displayed in the different fields : 
```js
{
    username: 'my-username'
}
```

**errors**  
Literal object representing the errors : 
```js
{
    username: ['this field is required.']
}
```

**visibleErrors**  
Literal object representing the errors displayed : 
```js
{
    username: true
}
```

### Events
**fieldChange**   
Emitted when the user is typing in an input for example.  
Parent component is responsible for updating the `model` prop accordingly : 
```
<FormGenerator
    :model="this.model"
    @fieldChange="({ field, value }) => this.model = Object.assign({}, this.model, { [field.model]: value })"
    <!-- ... -->
```

**errorsChange**  
Emitted when a field validations messages change.  
Parent component can listen to the event to disabled "submit" button for example : 
```
<FormGenerator
    @errorsChange="({ errors }) => this.errors = errors"
    <!-- ... -->
```
```
<button 
    :disabled="errors.length" 
    <!-- ... -->
```

**fieldFocus**  
Emitted when a field gains focus.  
```
<FormGenerator
    @fieldFocus="({ field }) => ..."
    <!-- ... -->
```

**fieldBlur**  
Emitted when a field loses focus.  
Useful to manipulate `visibleErrors`.
```
<FormGenerator
    @fieldBlur="({ field }) => ..."
    <!-- ... -->
```

### Accepted fields  
For the moment `FormGenerator` can only render these fields: 
- `checklist`
- `select`
- `checkbox`
- `radio`
- `input`
- `numeric-input`
- `textarea`
- `zipcode`
- `upload`
- `html`

New fields can easily be added to `FormGenerator.vue`  
Every field must have at least a `field` props, describing the field,  
And a  `value` prop describing its value.  
It must emit an event `valueChange` when the value changes.  

### Custom fields
Each field is wrapped in a slot.  
So you can easily create a custom field, or change an existing field behaviour.  

```
<FormGenerator
    :schema="{ field: [ { type: 'myCustomField', ... }, ... ] }"
    ...
>
    <template #myCustomField="{ field, value }">
        <!-- create your field here using {{ field }} and {{ value }} variables-->
    </template>
</FormGenerator>
```

### Validation
Validation is done when the model changes by calling the `validators` functions defined in each `schema.fields[].validators`

## Validators
Validators are defined in this file :  
https://github.com/Acadomia/aca-form-generator/blob/master/src/fieldValidators.js
Each validator is a function retuning `undefined` when the field value is valid.   
Or an array of error messages when something is invalid.  
The validator function takes 3 arguments:  
 - `field` the field whe want to validate
 - `model` all the values for the given form
 - `messages` a facultative object with the translated error messages.


### Usage
```js
import { fieldValidators } from 'aca-form-generator'

```
  
A minimal validator could look like this :  
```js
checked(field, model) {
    if (!model[field.model]) {
        return ['This checkbox must be checked']
    }
},
```

A more complete example would be:  

```js
checked(field, model, messages) {
    if (!model[field.model]) {
        return [messages.mustBeChecked]
    }
},
```

You can transate or customize the error messages using the function `withMessages`.  

```js

fieldValidators.checked.withMessages({
    mustBeChecked: 'Ce champ doit être coché.'
})
```

### Custom error
Using the scopped slot `errors` you can customize validation errors.    

```
<FormGenerator
    ...
>
    <template #errors="{ field, errors }">
        <!-- Display errors here, the way you want. -->
    </template>
</FormGenerator>
```


## Steps
Just like validators, to keep the code reusable, step logic is not coupled to the component `FormGenerator`  
  
The mixin `stepMixin.js` is here to help you handle multi step forms.   
You can find an example of how to use all these elements together to make a multistep form generated with a JSON comming from an API here :  
https://github.com/Acadomia/aca-form-generator/blob/master/src/screens/ExampleScreen.vue  
  
You can also find the code of the mixin here :    
https://github.com/Acadomia/aca-form-generator/blob/master/src/stepsMixin.js  

### Usage 
```js
import { stepsMixin } from 'aca-form-generator'
```

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