Add form type validation for date and number values along with interactive row highlighting in the main M&E Data Entry table

This commit is contained in:
Daniel S. Hansen
2025-08-25 14:15:04 -07:00
parent 39ce297af4
commit caad4e117e
@@ -116,12 +116,29 @@ const items = [
export function MEDataEntry() {
const [value, setValue] = useState("");
const [selection, setSelection] = useState([]);
const {
register,
handleSubmit,
reset,
watch,
formState: { errors },
} = useForm();
} = useForm({
defaultValues: {
id: "",
section: "",
volcano: "",
country: "",
start: "",
end: "",
type: "",
vpi10: "",
downstream: 0,
male: 0,
female: 0,
total: 0,
}
});
const onSubmit = (data) => {
console.log("Form submitted:", data);
@@ -184,12 +201,13 @@ export function MEDataEntry() {
<Box m={4} mt={1} border="1px solid" borderRadius="sm" borderColor="gray.500">
<Box m={4} border="1px solid">
<Box pl={1} bg="gray.200" border="1px solid" borderColor="gray.300" overflow="hidden">
<Box pl={1} bg="gray.200" border="1px solid" borderColor="gray.400" overflow="hidden">
Number of people benefitting from VDAP activities, disaggregate by sex
</Box>
<Box overflowX="auto">
<Table.Root variant="outline" size="sm">
{/* <Box overflowX="auto"> */}
<Table.ScrollArea borderWidth="1px"height="200px">
<Table.Root variant="outline" size="sm" stickyHeader interactive>
<Table.Header>
<Table.Row>
<Table.ColumnHeader /> {/* padding for checkboxes */}
@@ -211,7 +229,8 @@ export function MEDataEntry() {
{rows}
</Table.Body>
</Table.Root>
</Box>
</Table.ScrollArea>
{/* </Box> */}
</Box>
{/* Row actions aligned right */}
<HStack justify="flex-end" p={3} pt={0} borderBottom="1px solid" borderColor="gray.300" spacing={3} >
@@ -223,8 +242,13 @@ export function MEDataEntry() {
</HStack>
{/* Form Section */}
<Box m={4} border="1px solid">
<Box pl={1} bg="gray.200" border="1px solid" borderColor="gray.300" overflow="hidden">
<Box
as="form"
onSubmit={handleSubmit(onSubmit)}
m={4}
border="1px solid"
>
<Box pl={1} bg="gray.200" border="1px solid" borderColor="gray.400" overflow="hidden">
Fill in Form
</Box>
@@ -237,7 +261,7 @@ export function MEDataEntry() {
<Field.Root orientation="horizontal" flex="1" minW="260px">
<Field.Label>Start Date of Assistance:</Field.Label>
<Input {...register("startdate")} placeholder="9/6/1987" />
<Input {...register("startdate", { valueAsDate: true })} placeholder="9/6/1987" />
</Field.Root>
<Field.Root orientation="horizontal" flex="1">
@@ -254,29 +278,29 @@ export function MEDataEntry() {
<Field.Root orientation="horizontal" flex="1" minW="260px">
<Field.Label>End Date of Assistance:</Field.Label>
<Input {...register("enddate")} placeholder="7/14/2054" />
<Input {...register("enddate", { valueAsDate: true })} placeholder="7/14/2054" />
</Field.Root>
<Field.Root orientation="horizontal" flex="1">
<Field.Label>Downstream Affected Population:</Field.Label>
<Input {...register("downstream")} placeholder="1337" />
<Input {...register("downstream", { valueAsNumber: true })} placeholder="1337" />
</Field.Root>
</HStack>
<HStack spacing={6} align="flex-start" w="100%" flexWrap="wrap">
<Field.Root orientation="horizontal" flex="1" minW="260px">
<Field.Label>Male Population:</Field.Label>
<Input {...register("male")} placeholder="1776" />
<Input {...register("male", { valueAsNumber: true })} placeholder="1776" />
</Field.Root>
<Field.Root orientation="horizontal" flex="1" minW="260px">
<Field.Label>Female Population:</Field.Label>
<Input {...register("female")} placeholder="1892" />
<Input {...register("female", { valueAsNumber: true })} placeholder="1892" />
</Field.Root>
<Field.Root orientation="horizontal" flex="1">
<Field.Label>Total Population:</Field.Label>
<Input {...register("total")} placeholder="3668" />
<Input {...register("total", { valueAsNumber: true })} placeholder="3668" />
</Field.Root>
</HStack>
@@ -290,7 +314,7 @@ export function MEDataEntry() {
<Button type="submit" variant="solid" colorPalette="green" >
Add
</Button>
<Button type="submit">
<Button onClick={() => reset()}>
Reset
</Button>
</ButtonGroup>