support function type for date/time before/after options
This commit is contained in:
@@ -338,8 +338,8 @@ export function Number(
|
|||||||
* DATE
|
* DATE
|
||||||
*/
|
*/
|
||||||
interface ValidationDateOptions {
|
interface ValidationDateOptions {
|
||||||
before?: string;
|
before?: string | ((value: string) => string);
|
||||||
after?: string;
|
after?: string | ((value: string) => string);
|
||||||
invalidMessage?: string | ((options: ValidationDateOptions) => string);
|
invalidMessage?: string | ((options: ValidationDateOptions) => string);
|
||||||
invalidBeforeMessage?:
|
invalidBeforeMessage?:
|
||||||
| string
|
| string
|
||||||
@@ -381,8 +381,18 @@ export function Date(options?: ValidationDateOptions): ValidationDateObject {
|
|||||||
const parsedDate = parseAusDate(value);
|
const parsedDate = parseAusDate(value);
|
||||||
|
|
||||||
if (parsedDate != null) {
|
if (parsedDate != null) {
|
||||||
const beforeDate = parseAusDate(options?.before || "");
|
const beforeDate = parseAusDate(
|
||||||
const afterDate = parseAusDate(options?.after || "");
|
typeof (options["before"] = options?.before || "") ===
|
||||||
|
"function"
|
||||||
|
? options.before(value)
|
||||||
|
: options.before
|
||||||
|
);
|
||||||
|
const afterDate = parseAusDate(
|
||||||
|
typeof (options["after"] = options?.after || "") ===
|
||||||
|
"function"
|
||||||
|
? options.after(value)
|
||||||
|
: options.after
|
||||||
|
);
|
||||||
if (beforeDate != null && parsedDate > beforeDate) {
|
if (beforeDate != null && parsedDate > beforeDate) {
|
||||||
valid = false;
|
valid = false;
|
||||||
invalidMessageType = "invalidBeforeMessage";
|
invalidMessageType = "invalidBeforeMessage";
|
||||||
@@ -411,8 +421,8 @@ export function Date(options?: ValidationDateOptions): ValidationDateObject {
|
|||||||
* TIME
|
* TIME
|
||||||
*/
|
*/
|
||||||
interface ValidationTimeOptions {
|
interface ValidationTimeOptions {
|
||||||
before?: string;
|
before?: string | ((value: string) => string);
|
||||||
after?: string;
|
after?: string | ((value: string) => string);
|
||||||
invalidMessage?: string | ((options: ValidationTimeOptions) => string);
|
invalidMessage?: string | ((options: ValidationTimeOptions) => string);
|
||||||
invalidBeforeMessage?:
|
invalidBeforeMessage?:
|
||||||
| string
|
| string
|
||||||
@@ -453,8 +463,18 @@ export function Time(options?: ValidationTimeOptions): ValidationTimeObject {
|
|||||||
|
|
||||||
if (isValidTime(value)) {
|
if (isValidTime(value)) {
|
||||||
const parsedTime = convertTimeToMinutes(value);
|
const parsedTime = convertTimeToMinutes(value);
|
||||||
const beforeTime = convertTimeToMinutes(options?.before || "");
|
const beforeTime = convertTimeToMinutes(
|
||||||
const afterTime = convertTimeToMinutes(options?.after || "");
|
typeof (options["before"] = options?.before || "") ===
|
||||||
|
"function"
|
||||||
|
? options.before(value)
|
||||||
|
: options.before
|
||||||
|
);
|
||||||
|
const afterTime = convertTimeToMinutes(
|
||||||
|
typeof (options["after"] = options?.after || "") ===
|
||||||
|
"function"
|
||||||
|
? options.after(value)
|
||||||
|
: options.after
|
||||||
|
);
|
||||||
|
|
||||||
if (beforeTime != -1 && parsedTime > beforeTime) {
|
if (beforeTime != -1 && parsedTime > beforeTime) {
|
||||||
valid = false;
|
valid = false;
|
||||||
@@ -484,8 +504,8 @@ export function Time(options?: ValidationTimeOptions): ValidationTimeObject {
|
|||||||
* DATETIME
|
* DATETIME
|
||||||
*/
|
*/
|
||||||
interface ValidationDateTimeOptions {
|
interface ValidationDateTimeOptions {
|
||||||
before?: string;
|
before?: string | ((value: string) => string);
|
||||||
after?: string;
|
after?: string | ((value: string) => string);
|
||||||
invalidMessage?: string | ((options: ValidationDateTimeOptions) => string);
|
invalidMessage?: string | ((options: ValidationDateTimeOptions) => string);
|
||||||
invalidBeforeMessage?:
|
invalidBeforeMessage?:
|
||||||
| string
|
| string
|
||||||
@@ -531,8 +551,18 @@ export function DateTime(
|
|||||||
const parsedDate = parseAusDateTime(value);
|
const parsedDate = parseAusDateTime(value);
|
||||||
|
|
||||||
if (parsedDate != null) {
|
if (parsedDate != null) {
|
||||||
const beforeDate = parseAusDateTime(options?.before || "");
|
const beforeDate = parseAusDate(
|
||||||
const afterDate = parseAusDateTime(options?.after || "");
|
typeof (options["before"] = options?.before || "") ===
|
||||||
|
"function"
|
||||||
|
? options.before(value)
|
||||||
|
: options.before
|
||||||
|
);
|
||||||
|
const afterDate = parseAusDate(
|
||||||
|
typeof (options["after"] = options?.after || "") ===
|
||||||
|
"function"
|
||||||
|
? options.after(value)
|
||||||
|
: options.after
|
||||||
|
);
|
||||||
if (beforeDate != null && parsedDate > beforeDate) {
|
if (beforeDate != null && parsedDate > beforeDate) {
|
||||||
valid = false;
|
valid = false;
|
||||||
invalidMessageType = "invalidBeforeMessage";
|
invalidMessageType = "invalidBeforeMessage";
|
||||||
|
|||||||
Reference in New Issue
Block a user