-
-
Save catalinpit/6262a5b518ef9d9505aa869dbf3fa897 to your computer and use it in GitHub Desktop.
The form without any validation
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
import { useForm } from 'react-hook-form'; | |
export default function Form() { | |
const methods = useForm(); | |
return ( | |
<form | |
className="flex flex-col mt-10 bg-white px-4 py-5 shadow rounded-lg sm:m-6 sm:p-6 w-full lg:w-3/6 text-gray-600" | |
onSubmit={methods.handleSubmit((d) => console.log(d))} | |
> | |
<div className="flex flex-col mt-4"> | |
<label htmlFor="username">Username</label> | |
<input | |
className="mt-2 border-solid border-gray-300 border py-2 px-4 w-full rounded focus:outline-none focus:ring focus:ring-purple-500" | |
id="username" | |
{...methods.register('username')} | |
/> | |
</div> | |
<div className="flex flex-col mt-4"> | |
<label htmlFor="email">Email</label> | |
<input | |
className="mt-2 border-solid border-gray-300 border py-2 px-4 w-full rounded focus:outline-none focus:ring focus:ring-purple-500" | |
id="email" | |
{...methods.register('email')} | |
/> | |
</div> | |
<div className="mt-4"> | |
<label htmlFor="isAdmin">IsAdmin</label> | |
<input | |
className="ml-2" | |
id="isAdmin" | |
type="checkbox" | |
{...methods.register('isAdmin')} | |
/> | |
</div> | |
<div className="flex flex-col mt-4"> | |
<label htmlFor="createdAt">Creation Date</label> | |
<input | |
className="mt-2 border-solid border-gray-300 border py-2 px-4 w-full rounded focus:outline-none focus:ring focus:ring-purple-500" | |
id="createdAt" | |
type="date" | |
{...methods.register('createdAt')} | |
/> | |
</div> | |
<button | |
className="bg-purple-600 p-3 mt-12 rounded-lg text-white font-medium m-auto w-3/6 hover:opacity-75" | |
type="submit" | |
> | |
Submit | |
</button> | |
</form> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment