UNPKG

react-ocean-forms

Version:
67 lines (66 loc) 2.11 kB
/** * Copyright (c) 2018-present, Umweltbundesamt GmbH * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import { IFormContext } from '../components/FormContext'; import { TBasicFieldValue } from '../components/withField'; import { IMessageValues } from '../utils/stringFormatter'; /** * Enum representing the message id's for field errors. */ export declare enum FieldErrorMessageId { AlphaNumeric = "ojs_error_alphaNumeric", MaxLength = "ojs_error_maxLength", MinLength = "ojs_error_minLength", Required = "ojs_error_required" } /** * Error object for formatting errors through * the stringFormatter method */ export interface IFieldErrorObject { /** * Message id of the error or raw * error string */ message_id: string; /** * Optional parameters for the stringFormatter */ params: IMessageValues; } /** * Returns true if the given object implements * IFIeldErrorObject * @param object Object to test */ export declare function isIFieldErrorObject(object: any): object is IFieldErrorObject; /** * Possible return values of a validator */ export declare type TFieldError = undefined | string | IFieldErrorObject; /** * Possible error states of a validated component */ export declare type TFieldErrors = null | IFieldErrorObject | IFieldErrorObject[]; /** * Validator method type */ export declare type TValidator = ((value: TBasicFieldValue, context: IFormContext, ...args: unknown[]) => TFieldError); /** * Async validator method type */ export declare type TAsyncValidator = ((value: TBasicFieldValue, context: IFormContext, ...args: unknown[]) => Promise<TFieldError>); /** * Default validator type */ export interface IDefaultValidator extends TValidator { isDefaultValidator: true; } /** * Returns true if the given object is a IDefaultValidator * @param object Function to test */ export declare function isDefaultValidator(object: any): object is IDefaultValidator;