-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for actionless forms
- Loading branch information
1 parent
c37f4d2
commit 44b7f8d
Showing
7 changed files
with
107 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use client' | ||
|
||
import { useForm } from '@' | ||
import { actionlessSchema } from './schema' | ||
|
||
export const ActionlessForm = () => { | ||
const { connect, bindField, isPending, fieldErrors } = useForm({ | ||
schema: actionlessSchema, | ||
onSubmit: async (values) => { | ||
console.log('Submitting form with values:', values) | ||
return true | ||
} | ||
}) | ||
|
||
return ( | ||
<form {...connect()}> | ||
<label htmlFor='name'>Name</label> | ||
<input {...bindField('name')} /> | ||
{fieldErrors.name && <pre>{fieldErrors.name.first}</pre>} | ||
<br /> | ||
<label htmlFor='message'>Message</label> | ||
<textarea {...bindField('message')} /> | ||
{fieldErrors.message && <pre>{fieldErrors.message.first}</pre>} | ||
<br /> | ||
<label htmlFor='attachment'>Attachment (optional)</label> | ||
<input type='file' {...bindField('attachment')} /> | ||
{fieldErrors.attachment && <pre>{fieldErrors.attachment.first}</pre>} | ||
<button type='submit' disabled={isPending}> | ||
Submit | ||
</button> | ||
<br /> | ||
</form> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { z } from 'zod' | ||
|
||
export const actionlessSchema = z.object({ | ||
name: z.string().min(3, 'Name must be at least 3 characters'), | ||
message: z.string().min(10, 'Message must be at least 10 characters'), | ||
attachment: z.instanceof(File).nullable() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters