A powerful, lightweight React form handling library with built-in validation, customizable styling, and intuitive components.
✅ Simple API - Intuitive component-based form handling
✅ Built-in Validation - Comprehensive validation rules out of the box
✅ Custom Validation - Create your own validation functions
✅ Real-time Error Handling - Display errors as users type
✅ TypeScript Support - Full type safety
✅ Customizable Styling - Use default styles or create your own
✅ Accessibility - Built with a11y in mind
✅ Small Footprint - Lightweight with minimal dependencies
npm install easy-form-handler
# or
yarn add easy-form-handlerimport { Form, Heading, Input, Password, Submit, validate } from "easy-form-handler";
import { useState } from "react";
const MyForm = () => {
// State to store form values
const [record, setRecord] = useState({
name: "",
email: "",
password: "",
});
// State to store validation errors
const [error, setError] = useState({
name: "",
email: "",
password: "",
});
// Form submission handler
const handleSubmit = async (data: object) => {
if (Object.keys(error).length === 0) {
// Process form submission
console.log("Form submitted", data);
}
};
return (
<Form onSubmit={handleSubmit} isActiveDefaultStyle={true}>
<Heading>Signup Form</Heading>
<Input
name="name"
type="text"
label="Name"
watch={setRecord}
rule={{
required: true,
max: 10,
string: true,
}}
error={error.name}
required
placeholder="Enter your name"
/>
<Input
name="email"
type="text"
label="Email"
watch={setRecord}
error={error.email}
required
placeholder="Enter your email"
rule={{
required: true,
email: true,
contains: ["gmail", "yahoo"]
}}
checkRuleOnBlur={true}
/>
<Password
name="password"
type="password"
label="Password"
watch={setRecord}
error={error.password}
required
placeholder="Enter your password"
checkRuleOnBlur={true}
autoComplete="new-password"
rule={{
required: true,
min: 8,
max: 20,
contains: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "!", "@", "#"],
}}
/>
<Submit value="Sign Up" />
</Form>
);
};Container component for all form elements
<Form
onSubmit={handleSubmit}
isActiveDefaultStyle={true}
className="my-custom-form"
>
{/* Form content */}
</Form>Text input with validation and error handling
<Input
name="email"
type="text"
label="Email Address"
watch={setRecord}
error={error.email}
required
placeholder="Enter your email"
rule={{
required: true,
email: true
}}
checkRuleOnBlur={true}
/>Password input with toggle visibility
<Password
name="password"
type="password"
label="Password"
watch={setRecord}
error={error.password}
required
placeholder="Enter your password"
rule={{
required: true,
min: 8,
max: 20
}}
/>Form heading with default styling
<Heading>Registration Form</Heading>Submit button with default styling
<Submit value="Register" />Easy Form Handler provides extensive validation rules:
required- Field must be present and not emptyrequired_if- Field must be present when another field has a specific valuerequired_with- Field must be present when any of the specified fields are presentrequired_without- Field must be present when any of the specified fields are missing
string- Field must be a stringisAlpha- Field must contain only alphabetic charactersnoSpecialChars- Field must not contain special characters
min- Minimum length or valuemax- Maximum length or valuebetween- Value must be between specified min and maxsize- Exact length or value
numeric- Field must be a numberinteger- Field must be an integerboolean- Field must be true/false or 0/1array- Field must be an arraydate- Field must be a valid datefile- Field must be a valid file pathimage- Field must be a valid image file
email- Field must be a valid email addressurl- Field must be a valid URLuuid- Field must be a valid UUIDip- Field must be a valid IP addressjson- Field must be valid JSONregex- Field must match the specified regexcontains- Field must contain specified stringsin- Field must be one of specified valuessame- Field must match another fielddifferent- Field must be different from another field
Easy Form Handler provides default styling that can be enabled/disabled with the isActiveDefaultStyle prop. You can easily apply custom styling by providing additional CSS classNames to any component.
All components are fully typed for maximum type safety.
interface InputProps {
name?: string;
type: string;
label?: string;
value?: string | number;
watch?: (val: any) => void;
error?: string;
required?: boolean;
placeholder?: string;
className?: string;
rule?: Record<string, any>;
checkRuleOnBlur?: boolean;
autoComplete?: string;
}MIT
