Develop ultra fast with Prismane 🎉

past

This validator checks if a date is in the past.

Basic Usage

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

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

useForm Hook Usage

function Demo() {
  const { handleSubmit, handleReset, register } = useForm({
    fields: {
      date: {
        value: "",
        validators: {
          past: (v: string) => past(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.