### Customize Form Field Rendering and Behavior with Remix Forms Source: https://context7.com/seasonedcc/remix-forms/llms.txt This example showcases how to customize the rendering and behavior of form fields using `SchemaForm`. It allows setting labels, placeholders, input types, options for enums, and global settings like `autoFocus` and `buttonLabel`. ```tsx import { SchemaForm } from 'remix-forms' import { z } from 'zod' const schema = z.object({ password: z.string().min(8), website: z.string().url(), birthDate: z.string(), bio: z.string().optional(), country: z.enum(['us', 'uk', 'ca']), notifications: z.boolean(), }) export default function CustomPropsForm() { return ( ) } ``` -------------------------------- ### UseFetcher Integration for Non-Navigating Submissions Source: https://context7.com/seasonedcc/remix-forms/llms.txt Facilitates non-navigating form submissions using React Router's `useFetcher`. This is ideal for modal forms, inline updates, or scenarios where the user should remain on the same page after submission. ```tsx import { SchemaForm } from 'remix-forms' import { useFetcher } from 'react-router' import { z } from 'zod' const schema = z.object({ name: z.string().min(1), email: z.string().email(), }) export default function FetcherForm() { const fetcher = useFetcher() return (
{ // Handle successful submission if (fetcher.formAction && formState.isDirty) { setFocus('name') // Focus first field reset() // Clear form } }} > {({ Field, Button, Errors }) => ( <>
) } ``` -------------------------------- ### Perform Mutation with Remix Forms Source: https://context7.com/seasonedcc/remix-forms/llms.txt Executes mutations at a lower level without automatic redirects. This is useful for custom response handling or non-navigating submissions when using `useFetcher`. It requires the request, schema, mutation function, and a context object. ```tsx import { performMutation } from 'remix-forms' import { applySchema } from 'composable-functions' import { json, redirect } from 'react-router' import type { Route } from './+types/profile' const schema = z.object({ name: z.string().min(1), bio: z.string().optional(), }) const mutation = applySchema(schema)(async (values, context) => { const user = await updateProfile(context.userId, values) return user }) export const action = async ({ request }: Route.ActionArgs) => { const userId = await getUserId(request) const result = await performMutation({ request, schema, mutation, context: { userId }, }) if (!result.success) { // Custom error handling return json( { errors: result.errors, values: result.values }, { status: 422 } ) } // Custom success handling await logActivity('profile_updated', result.data.id) return redirect('/profile') } ``` -------------------------------- ### Customizing Components in Remix Forms with Zod Source: https://context7.com/seasonedcc/remix-forms/llms.txt Learn how to replace default form components like inputs and selects with custom implementations in Remix Forms. This allows seamless integration with design systems or the addition of specialized functionality, using Zod for schema definition. ```tsx import { SchemaForm } from 'remix-forms' import { z } from 'zod' import * as RadixSelect from '@radix-ui/react-select' const schema = z.object({ name: z.string().min(1), country: z.enum(['us', 'uk', 'ca']), }) function CustomSelect({ name, options, value, onChange, ...props }: any) { return ( {options.map((option: any) => ( {option.label} ))} ) } function CustomInput({ error, ...props }: any) { return ( ) } export default function CustomComponentsForm() { return ( ( )} > {({ Field, Button }) => ( <> ))}