### Install Dependencies and Start Theme Development
Source: https://formkit.com/guides/create-a-tailwind-theme
Install project dependencies and start the development server for your FormKit theme. This command assumes you are using pnpm.
```bash
# or npm or yarn
pnpm install
pnpm dev
```
--------------------------------
### Install @formkit/addons
Source: https://formkit.com/inputs/multi-step
Install the addons package to use the multi-step plugin. This is the first step before registering the plugin.
```bash
yarn add @formkit/addons
```
--------------------------------
### Transfer List Full Example with Slots and Data Fetching
Source: https://formkit.com/inputs/transfer-list
Demonstrates a comprehensive transfer list setup with custom slots for displaying detailed option information and functions for fetching, paginating, and searching guest data.
```jsx
You can put any type of element inside a form, not just FormKit
inputs (although only FormKit inputs are included with the
submission).
Register!
{JSON.stringify(value, null, 2)}
>
)}
` tag.
```jsx
import { FormKit, createInput } from '@formkit/react'import OneTimePassword from './one-time-password.react.jsx'const otp = createInput(OneTimePassword)function FirstValueExample() {
const [values, setValues] = useState({})
return (
<>
setValues(value ?? {})}
>
{JSON.stringify(values, null, 2)}
>
)
}
```
--------------------------------
### FormKit Configuration with Icons
Source: https://formkit.com/plugins/floating-labels
A FormKit configuration example that includes the floating labels plugin and genesis icons.
```jsx
import { defineFormKitConfig } from '@formkit/react'import { genesisIcons } from '@formkit/icons'import { createFloatingLabelsPlugin } from '@formkit/addons'export default defineFormKitConfig({
plugins: [createFloatingLabelsPlugin()],
icons: {
...genesisIcons,
},
})
```
--------------------------------
### Full Registration Form Example
Source: https://formkit.com/inputs/form
A comprehensive example of a registration form using various FormKit input types, including text, email, password, and submit. It demonstrates custom validation messages, help text, and submission handling. The form's state is managed using React's `useState` hook.
```jsx
import { useState } from 'react'import { FormKit } from '@formkit/react'const styles = ` #registration-example { width: 420px; padding: 1.5em 1.5em 0 1.5em; border: 1px solid #e4e4e4;
border-radius: 1em;
margin: 0 auto 1em auto;
}
#registration-example.hide {
display: none;
}
#registration-example pre {
margin-bottom: 10px;
}
@media (min-width: 400px) {
#registration-example .double {
display: flex;
justify-content: space-between;
}
#registration-example .double > * {
width: calc(50% - 0.25em);
}
#registration-example .double > *:first-child {
margin-right: 0.5em;
}
}`function RegisterExample() {
const [submitted, setSubmitted] = useState(false)
async function submitHandler() {
await new Promise((resolve) => setTimeout(resolve, 1000))
setSubmitted(true)
}
return (
<>
{({ value }) => (
<>
Register!
You can put any type of element inside a form, not just FormKit
inputs (although only FormKit inputs are included with the
submission).
{JSON.stringify(value, null, 2)}
>
)}
{submitted ? (
Submission successful!
) : null}
>
)}
```
--------------------------------
### Barcode Input Configuration with Icons
Source: https://formkit.com/inputs/barcode
A FormKit configuration example that includes the barcode input and icons from the genesis set.
```javascript
import { defineFormKitConfig } from '@formkit/react'import { genesisIcons } from '@formkit/icons'import { barcode } from '@formkit/barcode'import '@formkit/barcode/genesis'export default defineFormKitConfig({
inputs: {
barcode,
},
icons: {
...genesisIcons,
},
})
```
--------------------------------
### FormKit Config with Pro and AutoAnimate Plugins
Source: https://formkit.com/plugins/auto-animate
Example FormKit configuration integrating both the Pro plugin and the AutoAnimate plugin.
```javascript
import { defineFormKitConfig } from '@formkit/react'
import { createProPlugin, inputs as proInputs } from '@formkit/pro'
import { genesisIcons } from '@formkit/icons'
import { createAutoAnimatePlugin } from '@formkit/addons'
const pro = createProPlugin('fk-52971f34220', proInputs)
export default defineFormKitConfig({
plugins: [pro, createAutoAnimatePlugin()],
icons: {
...genesisIcons,
},
})
```
--------------------------------
### Supplemental Step Component
Source: https://formkit.com/inputs/multi-step
Example React component for the 'Supplemental' step, containing a single textarea for additional information.
```javascript
import { FormKit } from '@formkit/react'
export default function StepThree() {
return (
)
}
```
--------------------------------
### Step Two Form Inputs
Source: https://formkit.com/plugins/multi-step
Example of inputs for the second step, featuring a textarea and radio buttons for user feedback.
```jsx
import { FormKit } from '@formkit/react'
export default function StepTwo() {
return (
<>
>
)
}
```
--------------------------------
### Autocomplete with Options
Source: https://formkit.com/inputs/autocomplete
Example of an autocomplete input with a predefined list of options. Ensure options are correctly formatted with 'label' and 'value'.
```javascript
const options = [
{ label: 'United States of America', value: 'US' },
{ label: 'United Kingdom', value: 'GB' },
{ label: 'Afghanistan', value: 'AF' },
{ label: 'Albania', value: 'AL' },
{ label: 'Algeria', value: 'DZ' },
{ label: 'American Samoa', value: 'AS' },
{ label: 'Andorra', value: 'AD' },
{ label: 'Angola', value: 'AO' },
{ label: 'Anguilla', value: 'AI' },
{ label: 'Antarctica', value: 'AQ' },
{ label: 'Antigua and Barbuda', value: 'AG' },
{ label: 'Argentina', value: 'AR' },
{ label: 'Armenia', value: 'AM' },
{ label: 'Aruba', value: 'AW' },
{ label: 'Australia', value: 'AU' },
{ label: 'Austria', value: 'AT' },
{ label: 'Azerbaijan', value: 'AZ' },
{ label: 'Bahamas', value: 'BS' },
{ label: 'Bahrain', value: 'BH' },
{ label: 'Bangladesh', value: 'BD' },
{ label: 'Barbados', value: 'BB' },
{ label: 'Belarus', value: 'BY' },
{ label: 'Belgium', value: 'BE' },
{ label: 'Belize', value: 'BZ' },
{ label: 'Benin', value: 'BJ' },
{ label: 'Bermuda', value: 'BM' },
{ label: 'Bhutan', value: 'BT' },
{ label: 'Bolivia', value: 'BO' },
{ label: 'Bosnia and Herzegovina', value: 'BA' },
{ label: 'Botswana', value: 'BW' },
{ label: 'Bouvet Island', value: 'BV' },
{ label: 'Brazil', value: 'BR' },
{ label: 'British Indian Ocean Territory', value: 'IO' },
{ label: 'British Virgin Islands', value: 'VG' },
{ label: 'Virgin Islands, U.S.', value: 'VI' },
{ label: 'Wallis and Futuna', value: 'WF' },
{ label: 'Western Sahara', value: 'EH' },
{ label: 'Yemen', value: 'YE' },
{ label: 'Zambia', value: 'ZM' },
{ label: 'Zimbabwe', value: 'ZW' },
]
```
--------------------------------
### NBA All Time Starting Five Static List
Source: https://formkit.com/inputs/list
Use a static list to group related inputs where each input's value becomes an element in an array. This example uses autocomplete inputs for selecting NBA players for a starting five.
```html
NBA All Time Starting Five
{({ value }) => ( <> {JSON.stringify(value, null, 2)} > )}
```
--------------------------------
### Create FormKit Theme CLI Command
Source: https://formkit.com/guides/create-a-tailwind-theme
Initialize a new FormKit theme project using the provided starter theme. This command downloads a functional Vite application with structural styles and comments.
```bash
npx formkit@latest create-theme
```
--------------------------------
### FormKit Configuration with Addons and Icons
Source: https://formkit.com/inputs/multi-step
Example FormKit configuration file including the multi-step plugin, genesis icons, and custom root classes.
```javascript
import { defineFormKitConfig } from '@formkit/react'
import { genesisIcons } from '@formkit/icons'
import { createMultiStepPlugin } from '@formkit/addons'
import { rootClasses } from '~/formkit.theme'
export default defineFormKitConfig({
plugins: [createMultiStepPlugin()],
icons: {
...genesisIcons,
},
config: {
rootClasses,
},
})
```
--------------------------------
### Basic Time Input Example
Source: https://formkit.com/inputs/time
Demonstrates a simple time input with a label and help text. The `value` prop sets the initial time.
```html
```
--------------------------------
### Configure FormKit with Pro Plugin and Icons
Source: https://formkit.com/essentials/styling
Set up the FormKit configuration with the Pro plugin and Genesis icons. This example demonstrates how to import necessary components and define the configuration object for advanced features.
```javascript
import { genesisIcons } from '@formkit/icons'
import { defineFormKitConfig } from '@formkit/react'
import { createProPlugin, inputs as proInputs } from '@formkit/pro'
const pro = createProPlugin(import.meta.env.VITE_FORMKIT_PRO_KEY, proInputs)
export default defineFormKitConfig({
plugins: [pro],
icons: {
...genesisIcons,
},
})
```
--------------------------------
### Taglist Input Example
Source: https://formkit.com/inputs/taglist
This is a basic example of a FormKit Taglist input. It displays a list of countries that can be selected.
```vue
const countries = [
{ label: 'Virgin Islands, U.S.', value: 'VI' },
{ label: 'Wallis and Futuna', value: 'WF' },
{ label: 'Western Sahara', value: 'EH' },
{ label: 'Yemen', value: 'YE' },
{ label: 'Zambia', value: 'ZM' },
{ label: 'Zimbabwe', value: 'ZW' },
]
```
--------------------------------
### Install a Published FormKit Theme
Source: https://formkit.com/guides/create-a-tailwind-theme
Install a third-party FormKit theme as a dev dependency in your project using pnpm.
```bash
pnpm add -D formkit-theme-my-theme
```
--------------------------------
### Dropdown Input Examples
Source: https://formkit.com/inputs/dropdown
Demonstrates single-select and multi-select dropdowns with different selection appearance options. Requires the 'countries' data import.
```javascript
import countries from '../_data/countries.js'function DropdownExample() {
return (
<>
>
)
}
```
--------------------------------
### Multi-select Input Example
Source: https://formkit.com/inputs/autocomplete
This example demonstrates a multi-select input. When the `multiple` prop is set, the `value` prop must be an array.
```vue
[
{ label: 'Virgin Islands, British',
value: 'VG' },
{ label: 'Virgin Islands, U.S.',
value: 'VI' },
{ label: 'Wallis and Futuna',
value: 'WF' },
{ label: 'Western Sahara',
value: 'EH' },
{ label: 'Yemen',
value: 'YE' },
{ label: 'Zambia',
value: 'ZM' },
{ label: 'Zimbabwe',
value: 'ZW' },
]
```
```json
{}
```
--------------------------------
### Basic Dynamic List Example
Source: https://formkit.com/inputs/list
Demonstrates a dynamic list for managing a guest list. It allows adding and removing guest names, with the current list state displayed below. Use this for simple array inputs where items can be added or removed.
```jsx
Guest list
{({ items, node, value }) => ( <> {items?.map((item, index) => ( node.input( value.filter((_, itemIndex) => itemIndex !== index) ) } sectionsSchema={{ suffixIcon: { $el: 'button', }, }} /> ))} node.input(value.concat(''))}> + Add another {JSON.stringify(value, null, 2)} > )}
```
--------------------------------
### Basic Mask Input Example
Source: https://formkit.com/inputs/mask
A basic example of a mask input for a phone number. It uses the '+' and '#' characters as tokens for the mask.
```html
```
--------------------------------
### Tag List Data Example
Source: https://formkit.com/inputs/taglist
This is an example of the data structure used for a tag list, typically for country selections. Ensure your data matches this format.
```javascript
[
{ label: 'Uzbekistan', value: 'UZ' },
{ label: 'Vanuatu', value: 'VU' },
{ label: 'Venezuela', value: 'VE' },
{ label: 'Viet Nam', value: 'VN' },
{ label: 'Virgin Islands, British', value: 'VG' },
{ label: 'Virgin Islands, U.S.', value: 'VI' },
{ label: 'Wallis and Futuna', value: 'WF' },
{ label: 'Western Sahara', value: 'EH' },
{ label: 'Yemen', value: 'YE' },
{ label: 'Zambia', value: 'ZM' },
{ label: 'Zimbabwe', value: 'ZW' },
]
```
--------------------------------
### Generate FormKit Theme File
Source: https://formkit.com/getting-started/installation
Generate a starter FormKit theme file using the FormKit CLI.
```bash
npx formkit@latest theme
```
--------------------------------
### IsSlotCondition Example
Source: https://formkit.com/api-reference/formkit-inputs
An example demonstrating a schema node that would return true for the `isSlotCondition` function. This checks if the current schema node is a slot condition.
```javascript
{
if: '$slot.name',
then: '$slot.name',
else: []
} // this schema node would return true.
```
--------------------------------
### Using defaultConfig with custom inputs
Source: https://formkit.com/guides/optimizing-for-production
Example of how to use the defaultConfig object syntax to provide configuration options for plugins, specifically adding a custom input.
```javascript
app.use(plugin, defaultConfig({
inputs: {
myInput: createInput(/* input options */)
}
}))
```
--------------------------------
### Install createThemePlugin in Custom FormKit Config
Source: https://formkit.com/essentials/icons
If not using FormKit's `defaultConfig`, you must manually install the `createThemePlugin` from `@formkit/themes` into your FormKit configuration's plugin array.
```javascript
import { defineFormKitConfig } from '@formkit/react'
import { createThemePlugin } from '@formkit/themes'
export default defineFormKitConfig({
plugins: [createThemePlugin()],
})
```
--------------------------------
### Reading Props and Configuration
Source: https://formkit.com/essentials/architecture
Illustrates the best practice of reading configuration and prop data from `node.props`. Explicitly defined props take precedence over configuration options.
```javascript
// @noErrors
import { createNode } from '@formkit/core'
const child = createNode({
props: {
flavor: 'cherry',
},
})
const parent = createNode({
type: 'group',
config: {
size: 'large',
flavor: 'grape',
},
children: [child],
})
console.log(child.props.size)
// outputs: 'large'
console.log(child.props.flavor)
// outputs: 'cherry'
```
--------------------------------
### Autocomplete Country Filtering Example
Source: https://formkit.com/inputs/autocomplete
This example demonstrates filtering a list of countries for an autocomplete input. Ensure the data is correctly formatted as an array of objects with 'label' and 'value' properties.
```javascript
{ label: 'Vanuatu', value: 'VU' }, { label: 'Venezuela', value: 'VE' }, { label: 'Viet Nam', value: 'VN' }, { label: 'Virgin Islands, British', value: 'VG' }, { label: 'Virgin Islands, U.S.', value: 'VI' }, { label: 'Wallis and Futuna', value: 'WF' }, { label: 'Western Sahara', value: 'EH' }, { label: 'Yemen', value: 'YE' }, { label: 'Zambia', value: 'ZM' }, { label: 'Zimbabwe', value: 'ZW' },
```
--------------------------------
### Group Validity Example
Source: https://formkit.com/inputs/group
Groups are aware of their children's validation state. This example shows how to conditionally display messages based on the overall validity of the group's children.
```html
Register
{({ state: { valid } }) => ( <> {!valid ? ( Your account details are not complete! ) : ( It all looks good 👍 )} > )}
```
--------------------------------
### Basic Datetime-local Input
Source: https://formkit.com/inputs/datetime-local
This example demonstrates a basic datetime-local input with a label, help text, and validation. The `validationVisibility` is set to 'live' to show errors as the user types.
```html
```
--------------------------------
### FormKit Setup Context Interface
Source: https://formkit.com/api-reference/formkit-vue
Defines the type for the FormKit component's Vue setup context, including attributes, emit functions, exposed properties, props, and slots.
```typescript
interface FormKitSetupContext> {
attrs: any;
emit: FormKitEvents;
expose(exposed:{}): void;
props:{
}&Props;
slots: Slots;
}
```
--------------------------------
### Accessing Other Inputs with $get
Source: https://formkit.com/essentials/schema
Use the `$get` function within the schema to access the context object of other FormKit inputs by their declared `id`. This enables conditional rendering based on input states.
```javascript
import { FormKitSchema } from '@formkit/react'
const schema = [
{
$cmp: 'FormKit',
props: {
type: 'select',
id: 'drink',
label: 'Drink',
placeholder: 'Pick your drink',
options: {
coffee: 'Drip coffee',
espresso: 'Espresso shot',
tea: 'Tea',
},
validation: 'required',
},
},
{
$cmp: 'FormKit',
if: '$get(drink).value',
props: {
type: 'radio',
label: '$: "Drink options (" + $get(drink).value + ")"',
options: {
if: '$get(drink).value === coffee',
then: ['Large', 'Medium', 'Small'],
else: {
if: '$get(drink).value === espresso',
then: ['Single shot', 'Double shot'],
else: ['Earl grey', 'Matcha', 'Green tea', 'Jasmine'],
},
},
},
},
]
function Example() {
return (
<>
Order a beverage
>
)
}
```