/** @packageDocumentation * @module Form */ import "./Form.scss"; import * as React from "react"; /** The available editors for the fields in a [[Form]]. * @beta */ export declare type FieldEditor = "textbox" | "multilinetextbox" | "dropdown" | "checkbox"; /** Interface used to define each [[Field]] in a [[Form]] * @beta */ export interface FieldDef { label?: string; editor?: FieldEditor; options?: string[] | { [key: string]: string; }; value?: any; } /** Key/value pairs for all the field values with key being the field HTML Id. * @beta */ export interface FieldValues { [key: string]: any; } /** The state data used by [[Form]] to hold state of each [[Field]] and the result of submit button processing. * @beta */ interface FormState { values: FieldValues; errorMsg: string; submitSuccess?: boolean; } /** * FormContextState combines the Form's state data with the callbacks used to update the value of the state data. * @beta */ export interface FormContextState extends FormState { setValues: (values: FieldValues) => void; } /** React context used by Form as a Provider and by the Fields as Consumers and updaters. * @beta */ export declare const FormContext: React.Context; /** Key/value pairs for all the field definitions to be displayed in a [[Form]]. * @beta */ export interface FieldDefinitions { [key: string]: FieldDef; } /** Properties that define [[Form]] including the callback to be called when the Submit button is pressed. * @beta */ export interface FormProps { /** Required async callback the processes the Form data and throws and Error if the data cannot be processed. */ handleFormSubmit: (values: FieldValues) => Promise; /** Definition used to create each Field in the Form. */ fields: FieldDefinitions; /** Optional label which will override default Submit button label. */ submitButtonLabel?: string; } /** Component used to create a Form using supplied properties to specify the fields of the Form. * @example * // Example of using a form as contents of a modal dialog. * export class ExampleForm extends React.Component { * public static open() { * const form = new ExampleForm({}); * ModalDialogManager.openDialog(form.render()); * } * * protected async handleSubmit(values: FieldValues): Promise { * await this.processFormSubmission(values); * ModalDialogManager.closeDialog(); * const msg = JSON.stringify(values); * IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, "Form Submitted", msg)); * } * * protected async processFormSubmission(values: FieldValues): Promise { * // if error occurs during async processing throw an Error and return error message back to form. * throw new Error("Error processing form"); * } * * protected handleCancel() { * ModalDialogManager.closeDialog(); * } * * public render() { * const fields: FieldDefinitions = { * Name: { * label: this._nameLabel, * editor: "textbox", * value: "John Smith", * }, * PickList: { * label: this._pickListLabel, * editor: "dropdown", * value: "one", * options: ["one", "two", "three", "four"], * }, * }; * * return ( *
* this.handleCancel()}> *
this.handleSubmit(values)} * fields={fields} * /> *
*
* ); * } * @beta */ export declare class Form extends React.Component { private _submitButtonLabel; private _errorPrefix; private _errorSuffix; constructor(props: FormProps); /** * Returns whether there is an errorMsg message in the state/context * @param errorMsg - The form errorMsg */ private haveError; private _setValues; private _handleSubmit; render(): JSX.Element; } export {}; //# sourceMappingURL=Form.d.ts.map