///
import * as React from 'react';
import { TreeNode } from './treenode';
export declare type FieldValues = any;
export declare type FieldErrors = any;
export declare type Error = any;
export interface Validation {
errors: Error[];
fieldErrors: FieldErrors;
valid: boolean;
}
export declare type FieldErrorsToProps = (fieldErrors: any[], props: any) => any;
export interface ConfigureFormRes {
eventName: string;
getValueFromEvent: (...args: any[]) => any;
defaultProp: string;
valueProp: string;
fieldErrorsToProps?: FieldErrorsToProps;
}
export declare type ConfigureForm = (childType: any, childProps: any) => ConfigureFormRes | undefined;
export interface InternalProps {
action: string;
method: string;
id: string;
className: string;
onChange: (fieldValues: FieldValues, validation?: Validation) => void;
onSubmit: (fieldValues: FieldValues, validation: Validation) => void;
/**
* @property propName
* The form scans all its children for this property. Any component found with
* this as a prop will be tracked by the form.
*/
propName: string;
/**
* @property showErrorsOnChange
* Tells the form if it should display errors via the `` component
* when the form is changed or not. When not provided, errors will only show
* when the form is submitted.
*
* field -> Errors are only shown for fields that have changed
* form -> Errors are shown for the entier form
*/
showErrorsOnChange: 'field' | 'form';
/**
* @property showErrorsOnSubmit
* Tells the form if it should display errors via the `` component
* when the form is changed or not. When not provided, errors will only show
* when the form is submitted.
*
* true -> (DEFAULT) All errors are shown when the form is submitted
* false -> No errors are shown when the form is submitted
*/
showErrorsOnSubmit: boolean;
/**
* @property fieldErrorsToProps
* A global handler for passing error states to fields. This is also
* present as an option in `configureForm` which lets you configure
* how individual inputs get passed error states.
*
* This callback gets called with the errors for a Component along with
* that components props. Whatever is returned is merged into the props
* of the component
*/
fieldErrorsToProps: FieldErrorsToProps;
/**
* @property debounceValidation
* When present, the form will wait this many millisecond before the validation
* for `onChange` is fired. This will not change the behavior of `onSubmit`
*/
debounceValidation: number;
/**
* @property configureForm
* Allows the caller to configure the form to serialize custom inputs.
* By default it works with standard HTML form components:
* input, radio, checkbox, textarea.
*/
configureForm: ConfigureForm;
/**
* @property removeValidators
* React will warn if we pass excess properties to components. Forms will optionally
* remove all validators from its tracked components
*
* true -> Removes validators
* false -> (DEFAULT) leaves validators untouched
*/
removeValidators: boolean;
/**
* @property removePropName
* React will warn if we pass excess properties to components. Forms will optionally
* remove whatever property it looks for when looking for fields to avoid this.
* true -> Removes property (`name` by default)
* false -> (DEFAULT) leaves property untouched
*/
removePropName: boolean;
/**
* @property noValidate
* true -> onSubmit will get call regardless of validation
* false -> (DEFAULT) onSubmit will get called only when form is valid
*/
noValidate: boolean;
}
export declare type Props = Partial;
export interface State {
errors: Error[];
}
export declare const defaultFieldErrorsToProps: FieldErrorsToProps;
export declare const defaultConfigureInput: ConfigureFormRes;
export declare class Form extends React.Component {
static defaultProps: Props;
state: {
errors: never[];
};
private form;
private dirtyNodes;
private tree;
private clear;
reset(): void;
clearFieldErrors: () => void;
showFieldErrors: () => void;
serialize: () => {
fieldValues: any;
validation: Promise<{
validatedTree: TreeNode[];
errors: any[];
valid: boolean;
fieldErrors: any;
}>;
};
private validate;
private onChange;
private onSubmit;
render(): JSX.Element;
}
export default Form;