function FormExampleProto()

in packages/palette-mantine-form/palette.tsx [45:88]


function FormExampleProto() {
  const form = useForm({
    initialValues: {
      email: "",
      boolean: false,
      object: {
        number: 0,
      },
    },
    validate: {
      email: isEmail('Invalid email'),
    },
  });

  const handleError = (errors: typeof form.errors) => {
    if (errors.email) {
      console.error("Please provide a valid email");
    }
  };

  const handleSubmit = (values: typeof form.values) => {
    console.log(values);
  };

  return (
    <form
      onSubmit={form.onSubmit(handleSubmit, handleError)}
      onReset={form.onReset}
    >
      <TextInput withAsterisk label="Email" {...form.getInputProps("email")} />

      <Checkbox
        mt="md"
        label="Boolean"
        {...form.getInputProps("boolean", { type: "checkbox" })}
      />

      <NumberInput label="Number" {...form.getInputProps("object.number")} />

      <Button type="submit">Submit</Button>
      <Button type="reset">Reset</Button>
    </form>
  );
}