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