Develop ultra fast with Prismane 🎉

future

This validator checks if a date is in the future.

Basic Usage

import { future } from "@prismane/core/validators";

console.log(future(new Date(Date.now() + 1))); // Will return null
console.log(future(new Date(Date.now() - 1))); // Will return an error`

useForm Hook Usage

function Demo() {
  const { handleSubmit, handleReset, register } = useForm({
    fields: {
      date: {
        value: "",
        validators: {
          future: (v: string) => future(new Date(v)),
        },
      },
    },
  });

  return (
    <Form
      onSubmit={(e: any) => {
        handleSubmit(e, (v: any) => console.log(v, ""));
      }}
      onReset={() => handleReset()}
      maw={300}
    >
      <NativeDateField
        placeholder="Enter date: "
        label="Date:"
        {...register("date")}
      />
      <Button type="submit">Submit</Button>
    </Form>
  );
}

API

Parameters

NameTypeDescription
dateDateThe date that will be validated.
fieldNamestring / undefinedThe name of the field.