Skip to Content
✨ Just dropped my UI Library — still cooking up some magic! Stay tuned & maybe… hire me  or sponsor me 😉 
DocumentationAdvanced Form

Advanced Form

A comprehensive form component that eliminates repetitive form development. Build complex, validated, multi-step forms through configuration instead of writing UI code.

Install Dependencies

npx
quickcode-ui add AdvancedForm

Core Capabilities

Configuration-Driven Development: Define forms through JSON configuration objects instead of writing repetitive form markup and validation logic.

Comprehensive Field Support: Built-in support for 16 field types including text, email, number, checkbox, radio, switch, select, multi-select, slider, range-slider, textarea, date, time, tel, url, file, and image inputs.

Advanced Validation System: Powered by Zod schema validation with automatic schema generation, real-time validation feedback, custom validation functions, and configurable error messages.

Multi-Step Form Support: Create wizard-style forms with progress indicators, step navigation, individual step validation, and smooth transitions between steps.

Responsive Layout System: Automatically adapts to different screen sizes with configurable grid layouts supporting 1, 2, or 3 columns based on screen width.

Loading States and Skeletons: Built-in loading states for form interactions and customizable skeleton components for data loading scenarios.

Extensible Architecture: Support for conditional fields, custom headers and footers, auto-save functionality, and comprehensive event handling.

Examples

Comprehensive Multi-Step Form

Demonstrates all field types, validation patterns, conditional logic, and stepper functionality in a complete three-step registration process.

Complete Advanced Form

Advanced Form Demo

Experience all form features in one place

1
2
3

Personal Info

Tell us about yourself

Job Application Form

Single-step form showcasing file upload validation, URL validation, and select field options for employment applications.

Job Application Form

Job Application

Apply for our open position

User Profile Form with API Integration

Profile editing form that fetches user data from RandomUser.me API, demonstrates form population with external data, includes image upload with preview, and shows real-time header updates.

Profile Form with Image Support

Edit Profile

Update your profile information

Component Properties

AdvancedFormProps

PropertyTypeDefaultDescription
fieldsFormField[][]Field configuration array for single-step forms
stepsFormStep[][]Step configuration array for multi-step forms
onSubmit(data: Record<string, any>) => void | Promise<void>RequiredFunction called when form is submitted with form data
onChange(data: Record<string, any>) => voidundefinedFunction called whenever any field value changes
initialValuesRecord<string, any>{}Initial values to populate form fields on mount
headerFormHeaderundefinedHeader configuration with title, description, and custom content
footerFormFooterundefinedFooter configuration with custom content
submitTextstring"Submit"Text displayed on the submit button
resetTextstring"Reset"Text displayed on the reset button
nextTextstring"Next"Text displayed on the next step button
backTextstring"Back"Text displayed on the back step button
showResetbooleanfalseWhether to display the reset button
showStepProgressbooleantrueWhether to show step progress indicators in multi-step forms
autoSavebooleanfalseEnable automatic saving of form data to localStorage
classNamestringundefinedAdditional CSS classes for the form container
stepperClassNamestringundefinedAdditional CSS classes for the stepper component
formClassNamestringundefinedAdditional CSS classes for the form element
loadingbooleanfalseLoading state that disables all form inputs
isSubmitLoadingbooleanfalseLoading state specifically for the submit button
isFormLoadingbooleanfalseLoading state that shows skeleton instead of form
skeletonPropsFormSkeletonPropsundefinedConfiguration for the loading skeleton appearance
logoReact.ReactNodeundefinedLogo or image to display above the form title

FormField Configuration

PropertyTypeDefaultDescription
idstringRequiredUnique identifier for the field used in form data
labelstringRequiredDisplay label shown above the input field
typeFieldTypeRequiredInput type that determines which component to render
placeholderstringundefinedPlaceholder text displayed inside input fields
descriptionstringundefinedHelper text displayed below the input field
optionsFormFieldOption[] | string[]undefinedOptions for select, radio, checkbox, and multi-select fields
validationFormFieldValidationundefinedValidation rules and error messages for the field
defaultValueanyundefinedDefault value to populate the field with
disabledbooleanfalseWhether the field should be disabled
hiddenbooleanfalseWhether the field should be hidden from display
classNamestringundefinedAdditional CSS classes for the field wrapper
conditional(values: Record<string, any>) => booleanundefinedFunction to conditionally show/hide field based on form data
sliderPropsSliderPropsundefinedAdditional configuration for slider and range-slider fields
inputPropsRecord<string, any>undefinedAdditional props passed directly to the input component

FormFieldValidation Options

PropertyTypeDefaultDescription
requiredbooleanfalseWhether the field must have a value
minnumberundefinedMinimum value for number and slider fields
maxnumberundefinedMaximum value for number and slider fields
minLengthnumberundefinedMinimum character length for text fields
maxLengthnumberundefinedMaximum character length for text fields
patternstringundefinedRegular expression pattern for validation
emailbooleanundefinedEnable built-in email validation
urlbooleanundefinedEnable built-in URL validation
custom(value: any) => string | nullundefinedCustom validation function returning error text
maxSizenumberundefinedMaximum file size in bytes for file fields
acceptedTypesstring[]undefinedAccepted file types for file and image fields
requiredErrorstringundefinedCustom error message for required validation
minLengthErrorstringundefinedCustom error message for minimum length
maxLengthErrorstringundefinedCustom error message for maximum length
minErrorstringundefinedCustom error message for minimum value
maxErrorstringundefinedCustom error message for maximum value
emailErrorstringundefinedCustom error message for email validation
urlErrorstringundefinedCustom error message for URL validation
patternErrorstringundefinedCustom error message for pattern validation
customFileErrorstringundefinedCustom error message for file validation

FormStep Configuration

PropertyTypeDefaultDescription
idstringRequiredUnique identifier for the step
titlestringRequiredDisplay title shown in the stepper
descriptionstringundefinedOptional description text for the step
fieldsFormField[]RequiredArray of field configurations for the step
classNamestringundefinedAdditional CSS classes for the step

FormSkeletonProps

PropertyTypeDefaultDescription
classNamestringundefinedAdditional CSS classes for the skeleton container
fieldsnumber6Number of skeleton fields to display
columns1 | 2 | 32Number of columns in the skeleton grid layout

Supported Field Types

All field types must include as const for proper TypeScript inference:

Text Input Fields

  • "text" as const - Standard text input
  • "email" as const - Email input with validation
  • "password" as const - Password input with security validation
  • "number" as const - Numeric input with min/max validation
  • "tel" as const - Phone number input with formatting
  • "url" as const - URL input with protocol validation

Date and Time Fields

  • "date" as const - Date picker input
  • "time" as const - Time picker input
  • "datetime-local" as const - Combined date and time picker

Selection Fields

  • "checkbox" as const - Single checkbox for boolean values
  • "radio" as const - Radio button group for single selection
  • "switch" as const - Toggle switch for boolean values
  • "select" as const - Dropdown select for single selection
  • "multi-select" as const - Multi-selection dropdown

Range and Content Fields

  • "slider" as const - Single value slider
  • "range-slider" as const - Dual value range slider
  • "textarea" as const - Multi-line text input

File Upload Fields

  • "file" as const - General file upload
  • "image" as const - Image upload with preview functionality

Image Field Type

The image field type provides specialized functionality for image uploads:

{ id: "profilePicture", label: "Profile Picture", type: "image" as const, validation: { required: false, maxSize: 2000000, acceptedTypes: [".jpg", ".jpeg", ".png", ".gif", ".webp"], }, defaultValue: "https://example.com/current-avatar.jpg", description: "Upload your profile picture (max 2MB)" }

Image Field Features:

  • Automatic image preview display
  • Support for existing image URLs as default values
  • File size validation in bytes
  • File type restriction by extension
  • Remove button for clearing selection
  • Responsive preview layout

Loading States and Skeletons

The form supports multiple loading states for different scenarios:

Form Interaction Loading

<AdvancedForm loading={true} isSubmitLoading={true} />

Data Loading with Skeleton

<AdvancedForm isFormLoading={loading} skeletonProps={{ fields: 8, columns: 2, showHeader: true, showSteps: false, }} />

The skeleton automatically detects if the form is stepped and adjusts accordingly. Skeleton props allow customization of the loading appearance without affecting the actual form structure.

Advanced Configuration Examples

Complete Validation Setup

const validationExample = { fields: [ { id: "username", label: "Username", type: "text" as const, placeholder: "Enter username", validation: { required: true, minLength: 3, maxLength: 20, pattern: "^[a-zA-Z0-9_]+$", requiredError: "Username is required", minLengthError: "Username must be at least 3 characters", maxLengthError: "Username cannot exceed 20 characters", patternError: "Username can only contain letters, numbers, and underscores", custom: (value) => { if (value?.toLowerCase().includes('admin')) { return "Username cannot contain 'admin'"; } return null; } }, }, { id: "email", label: "Email Address", type: "email" as const, validation: { required: true, emailError: "Please enter a valid email address", requiredError: "Email is required", }, }, { id: "age", label: "Age", type: "number" as const, validation: { required: true, min: 18, max: 120, requiredError: "Age is required", minError: "You must be at least 18 years old", maxError: "Please enter a valid age", }, }, { id: "profileImage", label: "Profile Photo", type: "image" as const, validation: { required: false, maxSize: 5000000, acceptedTypes: [".jpg", ".jpeg", ".png"], customFileError: "Image must be under 5MB and in JPG or PNG format", }, }, { id: "resume", label: "Resume", type: "file" as const, inputProps: { accept: ".pdf,.doc,.docx" }, validation: { required: true, maxSize: 10000000, requiredError: "Please upload your resume", customFileError: "Resume must be under 10MB and in PDF or Word format", }, }, { id: "bio", label: "Biography", type: "textarea" as const, validation: { required: false, minLength: 10, maxLength: 500, minLengthError: "Bio must be at least 10 characters if provided", maxLengthError: "Bio cannot exceed 500 characters", }, }, ], };

Custom Validation Logic

Password Confirmation Example

{ id: "confirmPassword", label: "Confirm Password", type: "password" as const, validation: { required: true, custom: (value, allValues) => { if (value !== allValues.password) { return "Passwords do not match"; } return null; } }, }

Project Code Validation Example

{ id: "projectCode", label: "Project Code", type: "text" as const, placeholder: "PRJ-YYYY-XXXX", validation: { required: true, custom: (value) => { if (!value?.startsWith("PRJ-")) { return "Project code must start with 'PRJ-'"; } if (!/^PRJ-\d{4}-[A-Z]{4}$/.test(value)) { return "Format must be PRJ-YYYY-XXXX (e.g., PRJ-2024-ABCD)"; } return null; } }, }

Conditional Field Display

{ id: "companyName", label: "Company Name", type: "text" as const, validation: { required: true, minLength: 2, }, conditional: (values) => values.userType === "business", }, { id: "companySize", label: "Company Size", type: "select" as const, options: [ { label: "1-10 employees", value: "small" }, { label: "11-50 employees", value: "medium" }, { label: "51+ employees", value: "large" }, ], conditional: (values) => values.userType === "business" && values.companyName, }
<AdvancedForm steps={formSteps} onSubmit={handleSubmit} header={{ title: "Account Setup", description: "Complete your profile in three easy steps", }} logo={"https://cat.png"} showStepProgress={true} autoSave={true} isFormLoading={isLoading} skeletonProps={{ fields: 6, columns: 2, showSteps: true, steps: 3, }} />

Real-Time Data Handling

Monitor and respond to form changes:

<AdvancedForm onChange={(data) => { console.log("Current form data:", data); if (data.userType === "business") { setShowCompanyFields(true); } if (data.country) { fetchCitiesForCountry(data.country); } setFormData(data); }} />

Auto-Save and Persistence

Enable automatic form data persistence:

<AdvancedForm autoSave={true} />

Auto-save functionality automatically generates storage keys based on form titles or step names. Data is saved on every field change and restored when the component mounts.

Key Benefits

Reduced Development Time: Eliminate repetitive form markup, validation logic, and state management code by using configuration-driven development.

Type Safety: Complete TypeScript support with comprehensive type definitions ensures compile-time error catching and excellent developer experience.

Accessibility Built-In: Forms include proper ARIA labels, keyboard navigation support, screen reader compatibility, and required field indicators automatically.

Performance Optimized: Efficient rendering with minimal re-renders, optimized validation cycles, and smart update patterns prevent performance bottlenecks.

Production Ready: Comprehensive error handling, loading state management, string trimming, edge case handling, and validation feedback ensure reliable form behavior.

Extensible Architecture: Easy to extend with custom field types, validation logic, and UI components while maintaining consistency across your application.

User Experience Focus: Smart button states, helpful error messages, loading indicators, and responsive design create intuitive form interactions.

The AdvancedForm component transforms form development from a repetitive, error-prone process into a streamlined configuration task, allowing developers to focus on business logic rather than form implementation details.

Last updated on