### Plugin 'setup' Option Example
Source: https://vueform.com/docs/plugins
Extend component properties and methods using the 'setup' option. This example hides all 'TextElement' components by default and adds a 'myRef' property.
```javascript
import { ref } from 'vue'
export default function myPlugin() {
return {
apply: 'TextElement',
setup(props, context, component) {
const myRef = ref('Hello World')
// Hides all text element by default
component.hidden.value = true
return {
...component,
myRef,
}
},
}
}
```
--------------------------------
### Install Vueform with Bun
Source: https://vueform.com/docs
Use this command to install Vueform using Bun. It will guide you through the setup process for Vite, Nuxt, Astro, or Laravel environments.
```bash
bun create vueform
```
--------------------------------
### Form Steps with Options API and setup
Source: https://vueform.com/docs/breaking-forms-into-steps
Example combining Vue's Options API with the `setup` function for form steps. This approach uses `mixins` and `data` to define the form structure.
```javascript
import { ref, h, resolveComponent } from 'vue'
import { Vueform, useVueform } from '@vueform/vueform'
export default {
mixins: [Vueform],
setup: useVueform,
data: () => ({
vueform: {
steps: {
first: {
label: 'First',
elements: ['first_input'],
labels: {
previous: {
props: ['step$'],
render: () => h('span', [
h(resolveComponent('AppIcon'), {
icon: ['far', 'arrow-left']
}),
h('Previous'),
])
},
// ...
}
},
// ...
},
// ...
}
})
}
```
--------------------------------
### Plugin 'install' Option Example
Source: https://vueform.com/docs/plugins
Execute custom logic after the configuration is resolved and before components are registered using the 'install' option. This example adds a variable to the global $vueform object.
```javascript
export default function myPlugin() {
return {
install(app, $vueform) {
// Adding new variable to global $vueform object
$vueform.foo = 'bar'
}
}
}
```
--------------------------------
### Install Vueform with pnpm
Source: https://vueform.com/docs
Use this command to install Vueform using pnpm. It will guide you through the setup process for Vite, Nuxt, Astro, or Laravel environments.
```bash
pnpm create vueform
```
--------------------------------
### Install Vueform with npm
Source: https://vueform.com/docs
Use this command to install Vueform using npm. It will guide you through the setup process for Vite, Nuxt, Astro, or Laravel environments.
```bash
npm create vueform@latest
```
--------------------------------
### Form Steps with Composition API
Source: https://vueform.com/docs/breaking-forms-into-steps
Example of implementing form steps using Vue's Composition API with the `useVueform` hook. It demonstrates defining the form structure within the `setup` function.
```javascript
import { ref, h, resolveComponent } from 'vue'
import { Vueform, useVueform } from '@vueform/vueform'
export default {
mixins: [Vueform],
setup: (props, context) => {
const form = useVueform(props, context)
const vueform = ref({
steps: {
first: {
label: 'First',
elements: ['first_input'],
labels: {
previous: {
props: ['step$'],
render: () => h('span', [
h(resolveComponent('AppIcon'), {
icon: ['far', 'arrow-left']
}),
h('Previous'),
])
},
// ...
}
},
// ...
},
// ...
})
return {
...form,
vueform,
}
}
}
```
--------------------------------
### Install Vueform with Yarn
Source: https://vueform.com/docs
Use this command to install Vueform using Yarn. It will guide you through the setup process for Vite, Nuxt, Astro, or Laravel environments.
```bash
yarn create vueform
```
--------------------------------
### Install @vueform/plugin-mask with bun
Source: https://vueform.com/docs/input-mask
Install the input mask plugin using bun.
```bash
bun install @vueform/plugin-mask
```
--------------------------------
### Install @vueform/plugin-mask with pnpm
Source: https://vueform.com/docs/input-mask
Install the input mask plugin using pnpm.
```bash
pnpm install @vueform/plugin-mask
```
--------------------------------
### Vueform Form Steps with Composition API and useVueform
Source: https://vueform.com/docs/breaking-forms-into-steps
Integrate FormSteps with the useVueform composable for advanced reactivity and setup in the Composition API. This example shows how to manage form configuration within the setup function.
```vue
```
--------------------------------
### Install Dependencies (bun)
Source: https://vueform.com/docs/tree-shaking
Installs necessary Vueform dependencies required for building from source using bun.
```bash
bun install autosize flatpickr locutus lodash sortablejs
```
--------------------------------
### Install @vueform/plugin-mask with yarn
Source: https://vueform.com/docs/input-mask
Install the input mask plugin using yarn.
```bash
yarn add @vueform/plugin-mask
```
--------------------------------
### Install @vueform/plugin-mask with npm
Source: https://vueform.com/docs/input-mask
Install the input mask plugin using npm.
```bash
npm install @vueform/plugin-mask
```
--------------------------------
### Plugin 'apply' Option with Regex
Source: https://vueform.com/docs/plugins
Use a regular expression to specify which Vueform components this plugin's 'setup' option should be applied to. This example applies to all components ending with 'Element'.
```javascript
export default function myPlugin() {
return {
apply: /^[a-zA-Z]+Element$/,
setup(props, context, component) { /* ... */ },
}
}
```
--------------------------------
### Install Dependencies (pnpm)
Source: https://vueform.com/docs/tree-shaking
Installs necessary Vueform dependencies required for building from source using pnpm.
```bash
pnpm add autosize flatpickr locutus lodash sortablejs
```
--------------------------------
### Install Dependencies (npm)
Source: https://vueform.com/docs/tree-shaking
Installs necessary Vueform dependencies required for building from source using npm.
```bash
npm install autosize flatpickr locutus lodash sortablejs
```
--------------------------------
### Vueform Tabs Configuration with useVueform (Options API)
Source: https://vueform.com/docs/breaking-forms-into-steps
This Options API example uses the `useVueform` setup function to manage a form with tabs. The tab structure and schema are defined within the `vueform` data property.
```vue
import { ref } from 'vue'
import { Vueform, useVueform } from '@vueform/vueform'
export default {
mixins: [Vueform],
setup: useVueform,
data: () => ({
vueform: {
tabs: {
first: {
label: 'First',
elements: ['first_input']
},
second: {
label: 'Second',
elements: ['second_input']
},
third: {
label: 'Third',
elements: ['third_input']
},
},
schema: {
first_input: { type: 'text', placeholder: 'First input' },
second_input: { type: 'text', placeholder: 'Second input' },
third_input: { type: 'text', placeholder: 'Third input' },
}
}
})
}
```
--------------------------------
### Set List Order Start
Source: https://vueform.com/docs/configuration
Globally configure whether lists should start their order from 0 or 1. Defaults to 1.
```javascript
// vueform.config.js
import { defineConfig } from '@vueform/vueform'
export default defineConfig({
orderFrom: 0,
// ...
})
```
--------------------------------
### Install Dependencies (yarn)
Source: https://vueform.com/docs/tree-shaking
Installs necessary Vueform dependencies required for building from source using yarn.
```bash
yarn add autosize flatpickr locutus lodash sortablejs
```
--------------------------------
### Plugin 'apply' Option with Array of Strings
Source: https://vueform.com/docs/plugins
Provide an array of component names to apply the plugin's 'setup' option to multiple specific components.
```javascript
apply: ['TextElement', 'TextareaElement'],
```
--------------------------------
### Options API with Composition API Setup
Source: https://vueform.com/docs/breaking-forms-into-steps
A hybrid approach using Options API for data and Composition API's `setup` for `useVueform`. The `vueform` data property contains the tab configuration and `onMounted` hook.
```javascript
import { ref } from 'vue'
import { Vueform, useVueform } from '@vueform/vueform'
export default {
mixins: [Vueform],
setup: useVueform,
data: () => ({
vueform: {
tabs: {
first: {
label: 'First',
elements: ['first_input'],
},
},
onMounted(form$) {
form$.tabs$ // returns FormTabs component instance
form$.tabs$.tabs$.first // returns FormTab component instance named `first`
},
// ...
}
}),
}
```
--------------------------------
### Define Form Steps (Options API with Composition API setup)
Source: https://vueform.com/docs/breaking-forms-into-steps
Define form steps in `data` while using Composition API's `setup` for other logic. Access FormSteps and FormStep instances via `form$.steps$` and `form$.steps$.steps$.` respectively.
```javascript
import { ref } from 'vue'
import { Vueform, useVueform } from '@vueform/vueform'
export default {
mixins: [Vueform],
setup: useVueform,
data: () => ({
vueform: {
steps: {
first: {
label: 'First',
elements: ['first_input'],
},
},
onMounted(form$) {
form$.steps$ // returns FormSteps component instance
form$.steps$.steps$.first // returns FormStep component instance named `first`
},
// ...
}
}),
}
```
--------------------------------
### Project Configuration
Source: https://vueform.com/docs/configuration
Set global configuration options for Vueform in the vueform.config.js file. This example includes theme, locales, and locale settings.
```javascript
// vueform.config.js
import { defineConfig } from '@vueform/vueform'
import vueform from '@vueform/vueform/themes/vueform'
import en from '@vueform/vueform/locales/en'
export default defineConfig({
theme: vueform,
locales: { en },
locale: 'en',
})
```
--------------------------------
### Basic Vueform Component Configuration
Source: https://vueform.com/docs/rendering-forms
This snippet shows a basic Vueform component setup using mixins and setup functions. It defines a schema for email and password fields.
```javascript
export default {
mixins: [Vueform],
setup: useVueform,
data: () => ({
vueform: {
schema: {
email: { type: 'text', label: 'Email' },
password: { type: 'text', inputType: 'password', label: 'Password' },
}
}
}),
// TIP:
mounted() {
// Vueform props and methods are available via `this`:
const formData = this.data
this.el$(/*...*/)
this.update(/*...*/)
}
}
```
--------------------------------
### Plugin 'apply' Option with Array of Regex
Source: https://vueform.com/docs/plugins
Use an array of regular expressions to apply the plugin's 'setup' option to a broader set of components matching multiple patterns.
```javascript
apply: [/^[a-zA-Z]+Element/, /^Element[a-zA-Z]+$/],
```
--------------------------------
### Plugin 'props' Option Example
Source: https://vueform.com/docs/plugins
Extend the component's prop list using the 'props' option. This example adds a 'format' prop to the 'TextElement' component.
```javascript
export default function myPlugin() {
return {
apply: 'TextElement',
props: {
format: {
type: String,
required: false,
}
}
}
}
```
--------------------------------
### Vuex Store Setup
Source: https://vueform.com/docs/handling-form-data
Register a Vuex object in state and a mutation to update form data.
```javascript
// stores/forms.js
export default {
state: {
forms: {
registration: {}
}
},
mutations: {
UPDATE_FORM_DATA(state, value) {
state.forms[value.form] = value.data
}
}
}
```
--------------------------------
### Plugin 'config' Option Example
Source: https://vueform.com/docs/plugins
Modify the default Vueform configuration using the 'config' option. This example adds a new config value and applies a preset.
```javascript
import myPreset from 'my-preset'
export default function myPlugin() {
return {
config(config) {
// Adds a new config value
config.foo = 'bar'
// Applies `myPreset` by default to all Vueform instances
config.presets.myPreset = myPreset
config.usePresets.push('myPreset')
}
}
}
```
--------------------------------
### Pinia Store Setup
Source: https://vueform.com/docs/handling-form-data
Define a Pinia store to manage form data.
```javascript
// stores/forms.js
import { defineStore } from 'pinia'
export const useFormsStore = defineStore('forms', {
state: () => {
return {
registration: {}
}
},
})
```
--------------------------------
### LoginForm SFC with Inline Elements
Source: https://vueform.com/docs/rendering-forms
This example defines a LoginForm as a Single File Component (SFC) using inline elements within the template. It leverages Vueform mixins and setup for core functionality.
```vue
```
--------------------------------
### TextElement with Props
Source: https://vueform.com/docs/rendering-forms
Example of configuring a TextElement with various props like label and placeholder.
```vue
```
--------------------------------
### Copy and Extend EditorElement (Script)
Source: https://vueform.com/docs/creating-elements
Copy an existing element like EditorElement by extending its properties and overriding its setup function. Ensure the setup function is manually called and its return value is exported.
```vue
```
--------------------------------
### Using Generic Element Methods in Setup
Source: https://vueform.com/docs/creating-elements
Access the GenericElement's API, including methods like 'update', through the 'element' property in the context object within the setup function. This allows you to programmatically control element behavior.
```vue
```
--------------------------------
### After Date Validation Rule Examples
Source: https://vueform.com/docs/validating-elements
Provides examples of using the 'after' validation rule for dates. It shows how to specify an exact date, a relative date ('today'), or reference another element's date.
```javascript
// being an exact date
'after:2018-01-01'
// being a relative date
'after:today'
// being an other elements's path
'after:checkin_date'
```
--------------------------------
### Dynamic Class Combination Example
Source: https://vueform.com/docs/styles-and-layout
Illustrates how static and dynamic classes are combined for the input element in the 'tailwind' theme, considering size and enabled state.
```javascript
input: `w-full form-border form-border-color z-1 transition-shadow
addon-before:form-rounded-l-none outline-none
addon-after:form-rounded-r-none ` // from `input`
+ `form-p-input form-rounded ` // from `input_md`
+ `focus:form-ring` // from `input_enabled`
```
--------------------------------
### Formatted Submitted Data Example
Source: https://vueform.com/docs/handling-form-data
Illustrates the structure of data after being processed by the `format-data` functions.
```javascript
{
name: 'JOHN DOE
',
email: 'john@doe.com
'
}
```
--------------------------------
### Listing All Generic Properties and Methods
Source: https://vueform.com/docs/creating-elements
Log all available properties and methods of the GenericElement to the console using Object.keys(element) within the setup function. This is useful for exploration and understanding the full API.
```vue
```
--------------------------------
### Set Default Provider Options
Source: https://vueform.com/docs/configuration
Configure default options for registered providers. This example shows setting the `sitekey` for the `recaptcha2` provider.
```javascript
// vueform.config.js
import { defineConfig } from '@vueform/vueform'
export default defineConfig({
providerOptions: {
recaptcha2: {
sitekey: '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI',
}
},
// ...
})
```
--------------------------------
### Defining Form Steps in Options API
Source: https://vueform.com/docs/breaking-forms-into-steps
Example of defining form steps using the Options API in Vue. This includes setting up the 'first' step with custom previous button rendering.
```javascript
export default {
data: () => ({
forms: {
steps: {
first: {
label: 'First',
elements: ['first_input'],
labels: {
previous: {
props: ['step$'],
render: () => h('span', [
h(resolveComponent('AppIcon'), {
icon: ['far', 'arrow-left']
}),
h('Previous'),
])
},
// ...
}
},
// ...
},
// ...
}
})
}
```
--------------------------------
### Main JS File Default
Source: https://vueform.com/docs/tree-shaking
Default setup for a main JavaScript file (e.g., main.js) to integrate Vueform with a Vue application.
```javascript
// eg. main.js
import Vueform from '@vueform/vueform'
import vueformConfig from './vueform.config'
const app = createApp(App)
app.use(Vueform, vueformConfig)
app.mount('#app')
```
--------------------------------
### Define Form Steps with Basic Labels
Source: https://vueform.com/docs/breaking-forms-into-steps
Use the 'steps' object in the form configuration to define individual steps. Each step can have a 'label' and a list of 'elements'. This example shows basic string labels.
```vue
```
```vue
```
--------------------------------
### Exists Validation Backend Request Example
Source: https://vueform.com/docs/validating-elements
Demonstrates how backend parameters are structured for the 'exists' validation rule, including dynamic parameter values from form fields.
```php
$params = $_REQUEST['params'];
$type = $params[0]; // will be 'users'
```
```php
$value = $_REQUEST['value']; // the value of the input field
$name = $_REQUEST['name']; // the name of the input field
$params = $_REQUEST['params'];
$type = $params[0];
switch($type) {
case 'users':
return ... // check value against users
case 'product_identifiers':
return ... // check value against product identifiers
case 'slugs':
return ... // check value against slugs
}
```
```javascript
// request params sent to `exists` endpoint
requestParams: {
value: 'john@doe.com',
name: 'email',
params: [
'users',
5984
]
}
```
```php
$value = $_REQUEST['value']; // the value of the input field - 'john@doe.com'
$name = $_REQUEST['name']; // the name of the input field - 'email'
$params = $_REQUEST['params'];
$type = $params[0]; // will be 'users'
$id = $params[1]; // will be the value of the 'id' field in the same form - 5984
```
--------------------------------
### Pattern Mask with Incomplete Input Allowed
Source: https://vueform.com/docs/input-mask
This example demonstrates how to allow incomplete input for a pattern mask using the 'allowIncomplete' option. The mask '000-00-0000' is used for an SSN.
```vue
```
--------------------------------
### Math Expressions
Source: https://vueform.com/docs/expressions
Perform calculations and use operators directly within expressions to compute values dynamically. This example calculates total price.
```vue
```
--------------------------------
### Configure Form Steps (Composition API)
Source: https://vueform.com/docs/breaking-forms-into-steps
Set up form steps using `ref` and `useVueform` for Composition API.
```javascript
import { ref } from 'vue'
import { Vueform, useVueform } from '@vueform/vueform'
export default {
mixins: [Vueform],
setup: (props, context) => {
const form = useVueform(props, context)
const vueform = ref({
steps: {
first: {
label: 'First',
elements: ['first_input'],
buttons: {
previous: false,
}
},
// ...
},
// ...
})
return {
...form,
vueform,
}
}
}
```
--------------------------------
### Format Data Before Submit (Composition API)
Source: https://vueform.com/docs/handling-form-data
Use the `:format-data` option with a function to format form data. This example shows formatting for the entire form and individual elements.
```vue
```
--------------------------------
### Configure Form Steps with `useVueform` (Options API)
Source: https://vueform.com/docs/breaking-forms-into-steps
Integrate `useVueform` with Options API for form step configuration.
```javascript
import { ref } from 'vue'
import { Vueform, useVueform } from '@vueform/vueform'
export default {
mixins: [Vueform],
setup: useVueform,
data: () => ({
vueform: {
steps: {
first: {
label: 'First',
elements: ['first_input'],
buttons: {
previous: false,
}
},
// ...
},
// ...
}
})
}
```
--------------------------------
### Using LoginForm Component
Source: https://vueform.com/docs/rendering-forms
Demonstrates how to use a pre-defined LoginForm component within an application's template.
```html
```
--------------------------------
### Switch Locale on Vueform Installation
Source: https://vueform.com/docs/i18n
Set the default locale for Vueform when installing the plugin by passing the `locale` option. Ensure the desired locale is also included in the `locales` object in `vueform.config.js`.
```javascript
import Vue from 'vue'
import Vueform from '@vueform/vueform'
import vueformConfig from './../vueform.config'
Vue.use(Vueform, {
...vueformConfig,
locale: 'de'
})
```
--------------------------------
### Incorrect Regex Mask Example
Source: https://vueform.com/docs/input-mask
Avoid regex masks that only match the final input and not intermediary states, as this prevents users from typing. For example, '/^123$/' is incorrect because it doesn't allow '1' or '12'.
```vue
```
--------------------------------
### Get and Set Text Element Data (Options API)
Source: https://vueform.com/docs/handling-form-data
Access element data via `this.$refs.form$.el$(path)` to get or set values. This method is available after the component is mounted.
```vue
```
--------------------------------
### Define Form Steps (Composition API)
Source: https://vueform.com/docs/breaking-forms-into-steps
Define form steps using a `ref` in the `setup` function. Access FormSteps and FormStep instances via `form$.steps$` and `form$.steps$.steps$.` respectively.
```javascript
import { ref, onMounted } from 'vue'
import { Vueform, useVueform } from '@vueform/vueform'
export default {
mixins: [Vueform],
setup: (props, context) => {
const form = useVueform(props, context)
const vueform = ref({
steps: {
first: {
label: 'First',
elements: ['first_input'],
},
},
onMounted(form$) {
form$.steps$ // returns FormSteps component instance
form$.steps$.steps$.first // returns FormStep component instance named `first`
}
// ...
})
return {
...form,
vueform,
}
}
}
```
--------------------------------
### Accessing Generic Props in Custom Element Setup
Source: https://vueform.com/docs/creating-elements
Access custom and generic props within the `setup()` function of a custom element using the `props` argument. Transform props with `toRefs()` to maintain reactivity.
```vue
```
--------------------------------
### Pattern Mask Preventing Shift Back
Source: https://vueform.com/docs/input-mask
This example illustrates how to prevent the 'shift back' behavior in a pattern mask using a backtick `` ` ``. The second example prevents characters after the backtick from shifting back.
```vue
```
```vue
```
--------------------------------
### Single File Component Structure (Options API)
Source: https://vueform.com/docs/rendering-forms
Setting up a Single File Component to act as a Vueform, utilizing the Options API.
```vue
```
--------------------------------
### Accessing FormSteps and FormStep instances with useVueform (Options API)
Source: https://vueform.com/docs/breaking-forms-into-steps
In the Options API, after using `setup: useVueform`, the FormSteps and FormStep instances are available directly as `this.steps$` and `this.steps$.steps$.first` respectively within the `mounted` hook.
```vue
```
--------------------------------
### Vueform Component with Steps Configuration
Source: https://vueform.com/docs/breaking-forms-into-steps
This snippet shows the basic configuration of a Vueform component using steps, including event subscriptions for step navigation.
```javascript
export default {
mixins: [Vueform],
setup: useVueform,
data: () => ({
vueform: {
steps: {
first: {
label: 'First',
elements: ['first_input'],
},
},
// ...
}
}),
mounted() {
// Subscribe to FormSteps' @next event
this.steps$.on('next', (step$) => {
// ...
})
// Subscribe to `first` FormStep's @activate event
this.steps$.steps$.first.on('activate', (step$) => {
// ...
})
}
}
```
--------------------------------
### Replace Default Submit Endpoint
Source: https://vueform.com/docs/configuration
Example of how to override the default form submission endpoint in your Vueform configuration.
```javascript
// vueform.config.js
import { defineConfig } from '@vueform/vueform'
export default defineConfig({
endpoints: {
submit: {
url: '/form/submit',
method: 'post',
},
}
// ...
})
```
--------------------------------
### Configure Form Steps (Options API)
Source: https://vueform.com/docs/breaking-forms-into-steps
Define form steps and their configurations within the `data` object for Options API.
```javascript
export default {
data: () => ({
forms: {
steps: {
first: {
label: 'First',
elements: ['first_input'],
buttons: {
previous: false,
}
},
// ...
},
// ...
}
})
}
```
--------------------------------
### Set Default Views
Source: https://vueform.com/docs/configuration
Define the default views for each component in Vueform. This example sets the view for 'CheckboxgroupCheckbox' to 'tabs'.
```javascript
// vueform.config.js
import { defineConfig } from '@vueform/vueform'
export default defineConfig({
views: {
CheckboxgroupCheckbox: 'tabs'
},
// ...
})
```
--------------------------------
### Tailwind CSS Classes for ElementError
Source: https://vueform.com/docs/styles-and-layout
Example of default Tailwind CSS classes applied to the ElementError component's container.
```js
// @vueform/vueform/themes/tailwind/classes.js
export default {
// ...
ElementError: {
container: 'form-color-danger block',
container_sm: 'form-text-small-sm mt-0.5',
container_md: 'form-text-small mt-1',
container_lg: 'form-text-small-lg mt-1',
$container: (classes, { Size }) => ([
classes.container,
classes[`container_${Size}`],
]),
},
// ...
}
```
--------------------------------
### Using Rule Parameters with Global Registration
Source: https://vueform.com/docs/validating-elements
Demonstrates how to provide parameters to a globally registered custom rule using a colon and comma-separated values.
```vue
```
--------------------------------
### Vueform with Birthday Element
Source: https://vueform.com/docs/creating-elements
A basic example demonstrating the usage of the BirthdayElement within a Vueform component, including a validation rule.
```html
```
--------------------------------
### Single File Component Structure (Composition API)
Source: https://vueform.com/docs/rendering-forms
Setting up a Single File Component to act as a Vueform, utilizing the Composition API and useVueform hook.
```vue
```
--------------------------------
### Define Available Locales
Source: https://vueform.com/docs/configuration
Specify the available locales for your form. Ensure you import the locale data, for example, 'en' from '@vueform/vueform/locales/en'.
```javascript
// vueform.config.js
import { defaultConfig } from '@vueform/vueform'
import { en } from '@vueform/vueform/locales/en'
export default defineConfig({
locales: {
en,
},
// ...
})
```
--------------------------------
### Set Default Size
Source: https://vueform.com/docs/configuration
Configure the default size for all Vueform components. This example sets the default size to 'lg' (large).
```javascript
// vueform.config.js
import { defineConfig } from '@vueform/vueform'
export default defineConfig({
size: 'lg',
// ...
})
```
--------------------------------
### Define and Subscribe to Step Events (Options API)
Source: https://vueform.com/docs/breaking-forms-into-steps
Define steps in `data` and subscribe to `FormSteps` and `FormStep` events in `mounted`. Access component instances via `this.$refs.form$.steps$` and `this.$refs.form$.steps$.steps$.`.
```javascript
export default {
data: () => ({
steps: {
first: {
label: 'First',
elements: ['first_input']
},
},
// ...
}),
mounted() {
// Subscribe to FormSteps' @next event
this.$refs.form$.steps$.on('next', (step$) => {
// ...
})
// Subscribe to `first` FormStep's @activate event
this.$refs.form$.steps$.steps$.first.on('activate', (step$) => {
// ...
})
}
}
```
--------------------------------
### Functional Condition Example
Source: https://vueform.com/docs/conditional-rendering
Implements a custom functional condition using a JavaScript function that receives form and element instances.
```template
```
--------------------------------
### Computed Class Example ($container)
Source: https://vueform.com/docs/styles-and-layout
Illustrates how computed classes like '$container' work by dynamically resolving class names based on component properties such as 'Size'. It shows the resolved class names for different sizes.
```javascript
$container: (classes, { Size }) => (
[
classes.container, // returns 'vf-element-error vf-element-error-right'
classes[`container_${Size}`], // returns 'vf-element-error-sm' or '' or 'vf-element-error-lg'
]
)
```
```vue
```
--------------------------------
### Registering Official Plugin
Source: https://vueform.com/docs/plugins
Register an official Vueform plugin in your vueform.config.js file. Ensure the plugin is installed via npm or yarn.
```javascript
// vueform.config.js
import { defineConfig } from '@vueform/vueform'
import vueformPlugin from '@vueform/vueform-plugin'
export default defineConfig({
plugins: [
vueformPlugin,
],
// ...
})
```
--------------------------------
### Asynchronous Validation Rule Example
Source: https://vueform.com/docs/validating-elements
Validation rules can be asynchronous, such as the 'unique' rule which sends a request to an endpoint to check for value uniqueness.
```vue
```
--------------------------------
### Listen to Custom Events
Source: https://vueform.com/docs/creating-elements
Demonstrates how to listen to custom events emitted by a custom element, both inline in the template and via the schema configuration.
```html
```
```javascript
```
--------------------------------
### Accessing Array Values
Source: https://vueform.com/docs/expressions
Access array elements using dot notation with the index. For example, `{options.0}` refers to the first element.
```vue
```
--------------------------------
### Gallery View for File Preview
Source: https://vueform.com/docs/file-uploads
Utilize the 'view="gallery"' prop on FileElement to display file previews in a gallery format.
```vue
```
--------------------------------
### Override Component Templates
Source: https://vueform.com/docs/configuration
Globally replace component templates provided by the theme. This example shows how to replace the template for the 'ElementDescription' component.
```javascript
// vueform.config.js
import { defineConfig } from '@vueform/vueform'
import CustomElementDescription from '/path/to/custom/CustomElementDescription.vue'
export default defineConfig({
templates: {
ElementDescription,
}
// ...
})
```
--------------------------------
### Using LoginForm with Full Width Prop
Source: https://vueform.com/docs/rendering-forms
This example shows how to use the LoginForm component with the 'width' prop set to 'full', overriding the default element width and making them occupy the full available space.
```html
```
--------------------------------
### Basic Multilingual Form Setup
Source: https://vueform.com/docs/i18n
Enable multilingual support for your form to allow translation of elements. This will automatically display the FormLanguages component.
```vue
```
--------------------------------
### Configure Axios Instance for Vueform
Source: https://vueform.com/docs/configuration
Integrate an existing Axios instance by importing and exporting it. Ensure any necessary Axios configurations, like `withCredentials`, are set before passing the instance to Vueform.
```javascript
// vueform.config.js
import { defineConfig } from '@vueform/vueform'
import axios from 'axios'
axios.defaults.withCredentials = true
// ...
export default defineConfig({
axios,
// ...
})
```
--------------------------------
### Prepare Form Data Asynchronously (Options API)
Source: https://vueform.com/docs/handling-form-data
Shows how to use an `async` function for the `:prepare` option in the Options API. This function runs after validation and can cancel submission by throwing an error.
```vue
```
--------------------------------
### Customizing Element Validation Messages
Source: https://vueform.com/docs/validating-elements
Provides an example of replacing the default 'required' validation message for a specific TextElement using the ':messages' prop.
```vue
```
--------------------------------
### Logical Expressions (Ternary)
Source: https://vueform.com/docs/expressions
Use ternary expressions for conditional logic within expressions. This example determines an 'allowed' status based on age.
```vue
```