Skip to content

Commit d040bf6

Browse files
docs(form): add regle example (#5178)
Co-authored-by: Romain Hamel <[email protected]>
1 parent c744d6f commit d040bf6

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<script setup lang="ts">
2+
import { useRegle, type InferInput } from '@regle/core'
3+
import { required, email, minLength, withMessage } from '@regle/rules'
4+
import type { FormSubmitEvent } from '@nuxt/ui'
5+
6+
const { r$ } = useRegle({ email: '', password: '' }, {
7+
email: { required, email: withMessage(email, 'Invalid email') },
8+
password: { required, minLength: withMessage(minLength(8), 'Must be at least 8 characters') }
9+
})
10+
11+
type Schema = InferInput<typeof r$>
12+
13+
const toast = useToast()
14+
async function onSubmit(event: FormSubmitEvent<Schema>) {
15+
toast.add({ title: 'Success', description: 'The form has been submitted.', color: 'success' })
16+
console.log(event.data)
17+
}
18+
</script>
19+
20+
<template>
21+
<UForm :schema="r$" :state="r$.$value" class="space-y-4" @submit="onSubmit">
22+
<UFormField label="Email" name="email">
23+
<UInput v-model="r$.$value.email" />
24+
</UFormField>
25+
26+
<UFormField label="Password" name="password">
27+
<UInput v-model="r$.$value.password" type="password" />
28+
</UFormField>
29+
30+
<UButton type="submit">
31+
Submit
32+
</UButton>
33+
</UForm>
34+
</template>

docs/content/docs/2.components/form.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ links:
99

1010
## Usage
1111

12-
Use the Form component to validate form data using any validation library supporting [Standard Schema](https://github.com/standard-schema/standard-schema) such as [Valibot](https://github.com/fabian-hiller/valibot), [Zod](https://github.com/colinhacks/zod), [Yup](https://github.com/jquense/yup), [Joi](https://github.com/hapijs/joi) or [Superstruct](https://github.com/ianstormtaylor/superstruct) or your own validation logic.
12+
Use the Form component to validate form data using any validation library supporting [Standard Schema](https://github.com/standard-schema/standard-schema) such as [Valibot](https://github.com/fabian-hiller/valibot), [Zod](https://github.com/colinhacks/zod), [Regle](https://github.com/victorgarciaesgi/regle), [Yup](https://github.com/jquense/yup), [Joi](https://github.com/hapijs/joi) or [Superstruct](https://github.com/ianstormtaylor/superstruct) or your own validation logic.
1313

1414
It works with the [FormField](/docs/components/form-field) component to display error messages around form elements automatically.
1515

@@ -41,6 +41,14 @@ It requires two props:
4141
---
4242
::
4343

44+
::component-example{label="Regle"}
45+
---
46+
name: 'form-example-regle'
47+
props:
48+
class: 'w-60'
49+
---
50+
::
51+
4452
::component-example{label="Yup"}
4553
---
4654
name: 'form-example-yup'

docs/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"@nuxt/ui": "workspace:*",
2323
"@nuxtjs/plausible": "^2.0.1",
2424
"@octokit/rest": "^22.0.0",
25+
"@regle/core": "^1.9.5",
26+
"@regle/rules": "^1.9.5",
2527
"@vercel/analytics": "^1.5.0",
2628
"@vercel/speed-insights": "^1.2.0",
2729
"@vueuse/integrations": "^13.9.0",

pnpm-lock.yaml

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)