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
Name | Type | Description |
---|---|---|
date | Date | The date that will be validated. |
fieldName | string / undefined | The name of the field. |