|
| 1 | +--- |
| 2 | +title: Config |
| 3 | +description: Configure Nuxt Auto Form module |
| 4 | +--- |
| 5 | + |
| 6 | +You do not need to configure Nuxt Auto Form, but you can do so for finer-grained control |
| 7 | +you can override the config in the `nuxt.config.ts` file or per form basis. |
| 8 | + |
| 9 | +The configuration is merged using [defu](https://github.com/unjs/defu). |
| 10 | + |
| 11 | +## Global Configuration |
| 12 | + |
| 13 | +You can set global configuration options for the module in your `nuxt.config.ts` file in the `autoForm` field |
| 14 | +Here you should define your universal styles like submit button color. |
| 15 | + |
| 16 | +```ts [nuxt.config.ts] |
| 17 | +export default defineNuxtConfig({ |
| 18 | + modules: ['@norbiros/nuxt-auto-form'], |
| 19 | + fonts: { |
| 20 | + // Options |
| 21 | + } |
| 22 | +}) |
| 23 | +``` |
| 24 | + |
| 25 | +## Per-Form Configuration |
| 26 | + |
| 27 | +Sometimes you may want to override the global configuration for individual forms. |
| 28 | +You can do this by passing a `config` prop to the `<AutoForm>` component: |
| 29 | + |
| 30 | +```vue |
| 31 | +<template> |
| 32 | + <AutoForm |
| 33 | + :schema="schema" |
| 34 | + :config="{ |
| 35 | + submit: { |
| 36 | + component: 'CustomSubmitButton', |
| 37 | + }, |
| 38 | + }" |
| 39 | + /> |
| 40 | +</template> |
| 41 | +``` |
| 42 | + |
| 43 | +## Fields |
| 44 | + |
| 45 | +### `components` |
| 46 | + |
| 47 | +When a field in a form is rendered, the module automatically generates key |
| 48 | +```ts |
| 49 | +zodType._def.format ?? zodType._def.type |
| 50 | +``` |
| 51 | + |
| 52 | +This key is used to look up the component to render the field. |
| 53 | +You can override the default components used for rendering fields by specifying a mapping in the `components` option. |
| 54 | + |
| 55 | +::caution |
| 56 | +If you use string to define the component it **must** be [globally registered](https://nuxt.com/docs/4.x/guide/directory-structure/app/components#dynamic-components) to work. |
| 57 | +To do this, name your component with the `.global.vue` suffix, or place it in `components/global/` directory. |
| 58 | +:: |
| 59 | + |
| 60 | +``` |
| 61 | +components: { |
| 62 | + email: () => ({ component: 'UInput', componentProps: { type: 'email' } }), |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +For default values consult the source code. |
| 67 | + |
| 68 | +### `submit` |
| 69 | + |
| 70 | +This option allows you to customize the submit button used in forms. |
| 71 | + |
| 72 | +``` |
| 73 | +{ |
| 74 | + component?: undefined |
| 75 | + props?: Record<string, any> |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +If the component is unset, the props will be redefined to be the [`UButton`](https://ui.nuxt.com/components/button) props. |
0 commit comments