Skip to content

Commit 2556851

Browse files
docs: add Formisch to forms guide (#3953)
1 parent fc8900e commit 2556851

1 file changed

Lines changed: 110 additions & 2 deletions

File tree

website/src/content/pages/guides/forms.mdx

Lines changed: 110 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ description: A guide to building forms with Ark UI components.
55
---
66

77
Ark UI provides the `Field` and `Fieldset` components for integrating with native `form` element or popular form
8-
libraries like [React Hook Form](https://react-hook-form.com/), [TanStack Form](https://tanstack.com/form/latest), and
9-
[Vee Validate](https://vee-validate.logaretm.com).
8+
libraries like [React Hook Form](https://react-hook-form.com/), [TanStack Form](https://tanstack.com/form/latest),
9+
[Formisch](https://formisch.dev/), and [Vee Validate](https://vee-validate.logaretm.com).
1010

1111
## Field Context
1212

@@ -448,3 +448,111 @@ const Demo = () => {
448448
)
449449
}
450450
```
451+
452+
## Formisch
453+
454+
Formisch is a schema-based, headless form library that, like Ark UI, supports React, Solid, Vue, and Svelte. It
455+
validates with [Valibot](https://valibot.dev/) and infers all input and output types from the schema.
456+
457+
### Native Controls
458+
459+
Since Formisch also exports a `Field` component, import it under an alias to avoid a name clash with Ark UI's `Field`.
460+
461+
```tsx
462+
import { Field } from '@ark-ui/react/field'
463+
import { Field as FormischField, Form, useForm } from '@formisch/react'
464+
import * as v from 'valibot'
465+
466+
const FormSchema = v.object({
467+
firstName: v.pipe(v.string(), v.nonEmpty('First name is required')),
468+
email: v.pipe(v.string(), v.email('Invalid email address')),
469+
})
470+
471+
const Demo = () => {
472+
const form = useForm({ schema: FormSchema })
473+
474+
return (
475+
<Form of={form} onSubmit={(output) => console.log(output)}>
476+
<FormischField of={form} path={['firstName']}>
477+
{(field) => (
478+
<Field.Root invalid={field.errors !== null}>
479+
<Field.Label>First Name</Field.Label>
480+
<Field.Input {...field.props} value={field.input} />
481+
<Field.ErrorText>{field.errors?.[0]}</Field.ErrorText>
482+
</Field.Root>
483+
)}
484+
</FormischField>
485+
486+
<FormischField of={form} path={['email']}>
487+
{(field) => (
488+
<Field.Root invalid={field.errors !== null}>
489+
<Field.Label>Email</Field.Label>
490+
<Field.Input {...field.props} value={field.input} />
491+
<Field.ErrorText>{field.errors?.[0]}</Field.ErrorText>
492+
</Field.Root>
493+
)}
494+
</FormischField>
495+
496+
<button type="submit">Submit</button>
497+
</Form>
498+
)
499+
}
500+
```
501+
502+
### Custom Components
503+
504+
Use the `onChange` function of the field store to integrate custom form components like select or combobox.
505+
506+
```tsx
507+
import { Field } from '@ark-ui/react/field'
508+
import { Select, createListCollection } from '@ark-ui/react/select'
509+
import { Field as FormischField, Form, useForm } from '@formisch/react'
510+
import * as v from 'valibot'
511+
512+
const FormSchema = v.object({
513+
framework: v.pipe(v.string(), v.nonEmpty('Please select a framework')),
514+
})
515+
516+
const Demo = () => {
517+
const form = useForm({ schema: FormSchema })
518+
519+
const collection = createListCollection({
520+
items: ['React', 'Solid', 'Vue', 'Svelte'],
521+
})
522+
523+
return (
524+
<Form of={form} onSubmit={(output) => console.log(output)}>
525+
<FormischField of={form} path={['framework']}>
526+
{(field) => (
527+
<Field.Root invalid={field.errors !== null}>
528+
<Select.Root
529+
collection={collection}
530+
value={field.input ? [field.input] : []}
531+
onValueChange={(e) => field.onChange(e.value[0])}
532+
>
533+
<Select.Label>Framework</Select.Label>
534+
<Select.Control>
535+
<Select.Trigger>
536+
<Select.ValueText placeholder="Select a Framework" />
537+
</Select.Trigger>
538+
</Select.Control>
539+
<Select.Positioner>
540+
<Select.Content>
541+
{collection.items.map((item) => (
542+
<Select.Item key={item} item={item}>
543+
<Select.ItemText>{item}</Select.ItemText>
544+
</Select.Item>
545+
))}
546+
</Select.Content>
547+
</Select.Positioner>
548+
<Select.HiddenSelect />
549+
</Select.Root>
550+
<Field.ErrorText>{field.errors?.[0]}</Field.ErrorText>
551+
</Field.Root>
552+
)}
553+
</FormischField>
554+
<button type="submit">Submit</button>
555+
</Form>
556+
)
557+
}
558+
```

0 commit comments

Comments
 (0)