@open-formulieren/types
Advanced tools
Comparing version 0.22.0 to 0.23.0
@@ -0,1 +1,45 @@ | ||
/** | ||
* @file Types related to (client-side) formio validation and their error message overrides. | ||
* | ||
* This module is responsible for defining: | ||
* - the available validation constraints | ||
* - the corresponding (translatable) error codes. | ||
* | ||
* The `ValidateOptions` interface (which is extended/restricted for our needs) defines | ||
* the available validation constraints that can be used by a component. By using our custom | ||
* `OFValidateOptions` interface, one can define the available `validate` keys: | ||
* | ||
* ```ts | ||
* type TimeComponentSchema = SomeBaseComponent & {validate: OFValidateOptions<'min' | 'max'>}; | ||
* | ||
* // a component with such a type can be defined as: | ||
* const timeComponent: TimeComponentSchema = { | ||
* validate: { | ||
* minTime: '11:00', | ||
* maxTime: '13:00', | ||
* } | ||
* } | ||
* ``` | ||
* | ||
* Each validation constraint key can provide possible error keys if validation fails. This mapping | ||
* of constraint keys (e.g. `minTime`, `maxTime`) to the error keys is defined in `VALIDATOR_TO_ERROR_KEY`. | ||
* | ||
* This can be used when defining the error messages: | ||
* | ||
* ```ts | ||
* type TimeComponentSchema = SomeBaseComponent & {errors: ComponentErrors<ComponentErrorKeys<'minTime' | 'maxTime'>>}; | ||
* | ||
* // a component with such a type can be defined as: | ||
* const numberComponent: NumberComponentSchema = { | ||
* errors: { | ||
* minTime: 'Time should be greater than ...', | ||
* maxTime: 'Time should be lower than ...', | ||
* invalid_time: 'Invalid time', // Both `minTime` and `maxTime` provides the `invalid_time` error key. | ||
* } | ||
* } | ||
* ``` | ||
* | ||
* NOTE: In some places of the file, we refer to the validation constraint keys as "validator names". Those should | ||
* *NOT* be confused with validator keys used in the SDK (e.g. `timeMinMax`). | ||
*/ | ||
import { ValidateOptions } from 'formiojs'; | ||
@@ -10,6 +54,3 @@ declare module 'formiojs' { | ||
} | ||
/** | ||
* Types related to (client-side) formio validation and their error message overrides. | ||
*/ | ||
export type BaseErrorKeys = 'required' | 'min' | 'max' | 'maxLength' | 'invalid_email' | 'pattern' | 'minDate' | 'maxDate' | 'customMessage' | 'minSelectedCount' | 'maxSelectedCount' | 'minTime' | 'maxTime' | 'invalid_time'; | ||
export type BaseErrorKeys = 'required' | 'min' | 'max' | 'maxLength' | 'invalid_email' | 'pattern' | 'minDate' | 'maxDate' | 'customMessage' | 'minSelectedCount' | 'maxSelectedCount' | 'invalid_date' | 'minTime' | 'maxTime' | 'invalid_time' | 'invalid_datetime'; | ||
export type ComponentErrors<Keys extends BaseErrorKeys = BaseErrorKeys> = { | ||
@@ -30,4 +71,4 @@ [K in Keys]?: string; | ||
readonly maxSelectedCount: "maxSelectedCount"; | ||
readonly minDate: "minDate"; | ||
readonly maxDate: "maxDate"; | ||
readonly minDate: "minDate" | "invalid_date" | "invalid_datetime"; | ||
readonly maxDate: "maxDate" | "invalid_date" | "invalid_datetime"; | ||
readonly minTime: "minTime" | "invalid_time"; | ||
@@ -34,0 +75,0 @@ readonly maxTime: "maxTime" | "invalid_time"; |
{ | ||
"name": "@open-formulieren/types", | ||
"version": "0.22.0", | ||
"version": "0.23.0", | ||
"description": "Typescript type definitions for Open Forms' Form.io extensions", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51557
1314