UNPKG

react-ocean-forms

Version:
123 lines (122 loc) 3.85 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 React from 'react'; import { IBaseFormContext, IFieldValues } from '../FormContext'; import { IFormProps } from './Form.types'; interface IFormState<TFieldValues = IFieldValues> { context: IBaseFormContext<TFieldValues>; } /** * Wrapper for managed forms */ export declare class Form<TFieldValues = IFieldValues, TSubmitArgs = unknown> extends React.Component<IFormProps<TFieldValues, TSubmitArgs>, IFormState<TFieldValues>> { static displayName: string; static defaultProps: { defaultValues: {}; asyncValidationWait: number; asyncValidateOnChange: boolean; formatString: (id: string, values?: import("../../utils").IMessageValues | undefined) => string; disabled: boolean; plaintext: boolean; }; private readonly fields; private readonly eventListeners; constructor(props: IFormProps<TFieldValues>); /** * Returns the current state of the given field * @param name Field name * @returns Current field state or default field state */ private getFieldState; /** * Generates and returns an object that contains * all values from all the fields. * @returns Current values in form of { name: value, name2: value2, ... } */ private getValues; /** * Gets called when a field triggers an event * @param name Field name * @param event Event name * @param args Event args */ private notifyFieldEvent; /** * Notifies the event listeners about an event * @param name Field name * @param event Event name * @param args Event args */ private notifyListeners; /** * Handles the submit event of the form - prevents * the default and runs the submit logic * @param event Event object */ private handleSubmit; /** * Submits the form - triggers any validations if needed * and raises the onFormSubmit prop callback if the * form is currently valid. * @param submitArgs Arguments that will be passed * to the onSubmit callback */ private submit; /** * Updates the busy state in the form context * @param busy Busy state */ private updateBusyState; /** * Triggers the form wide validation callback if given * @returns Validation state of the form */ private triggerFormValidation; /** * Gathers all the data and calls the onSubmit callback * if provided. * @param submitArgs Arguments that will be passed * to the onSubmit callback */ private callOnSubmit; /** * Handles the reset event of the form - prevents * the default and sets the state of all fields back * to the default state. * @param event Event object */ private handleReset; /** * Sets the state of all fields back * to the default state. */ private reset; /** * Registers a new field to the form. * @param name Field name * @param fieldState Field state */ private registerField; /** * Unregisters a field from the form. * @param name Field name */ private unregisterField; /** * Combines the local form context with * the values from the props to form the * full form context passed to the form * components. */ private prepareFormContext; /** * Renders the form and wraps all its children * in a FormContext provider and a html form. */ render(): JSX.Element; } export {};