Add react-hook-forms to AccountCanvas

This commit is contained in:
Daniel S. Hansen
2025-08-04 16:02:06 -07:00
parent f19ddc1994
commit a43113d1d1
3 changed files with 43 additions and 13 deletions
@@ -1,13 +1,26 @@
import { Box, Flex, Field, Input, Stack, Switch, Text, Heading } from "@chakra-ui/react"
import { Box, Flex, Field, Input, Stack, Heading, Button } from "@chakra-ui/react"
import { useForm } from 'react-hook-form';
export default function AccountCanvas() {
const {
register,
handleSubmit,
watch,
formState: { errors },
} = useForm();
const onSubmit = (data) => {
console.log("Form submitted:", data);
}
console.log(watch("example")); // watch input value by passing the name of it
return (
<Flex
height="100vh"
direction="column"
align="start"
justify="start"
// hieght="100vh"
bg="gray.50"
pt={6}
pl={6}
@@ -15,6 +28,8 @@ export default function AccountCanvas() {
<Heading as="h1" mb={2}>Account</Heading>
<Box
as="form"
onSubmit={handleSubmit(onSubmit)}
border="1px solid"
borderColor="gray.300"
borderRadius="md"
@@ -31,31 +46,28 @@ export default function AccountCanvas() {
<Stack gap="6" maxW="sm" css={{ "--field-label-width": "96px" }}>
<Field.Root orientation="horizontal">
<Field.Label>User Name</Field.Label>
<Input placeholder="David Johnston" flex="1" />
<Input {...register("username")} placeholder="David Johnston" flex="1" />
</Field.Root>
<Field.Root orientation="horizontal">
<Field.Label> First Name</Field.Label>
<Input placeholder="David" flex="1" />
<Input {...register("firstname")} placeholder="David" flex="1" />
</Field.Root>
<Field.Root orientation="horizontal">
<Field.Label>Last Name</Field.Label>
<Input placeholder="Johnston" flex="1" />
<Input {...register("lastname")} placeholder="Johnston" flex="1" />
</Field.Root>
<Field.Root orientation="horizontal">
<Field.Label>Email</Field.Label>
<Input placeholder="djohntson@usgs.gov" flex="1" />
<Input {...register("email")} placeholder="djohntson@usgs.gov" flex="1" />
</Field.Root>
{/* <Field.Root orientation="horizontal">
<Field.Label>Hide email</Field.Label>
<Switch.Root>
<Switch.HiddenInput />
<Switch.Control />
</Switch.Root>
</Field.Root> */}
<Button type="submit">
Save
</Button>
</Stack>
</Box>
</Flex>