/** Copyright 2021 Forestry.io Holdings, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import { FormApi, Config, FormState } from 'final-form'; import { Plugin } from '@tinacms/core'; import { Field, AnyField } from './field'; export interface FormOptions extends Config { id: any; label: string; fields?: F[]; __type?: string; reset?(): void; actions?: any[]; buttons?: { save: string; reset: string; }; loadInitialValues?: () => Promise; onChange?(values: FormState): void; } export declare class Form implements Plugin { private _reset; __type: string; id: any; label: string; fields: F[]; finalForm: FormApi; actions: any[]; buttons: { save: string; reset: string; }; loading: boolean; constructor({ id, label, fields, actions, buttons, reset, loadInitialValues, onChange, ...options }: FormOptions); /** * A unique identifier for Forms. * * @alias id */ get name(): any; /** * Returns the current values of the form. * * if the form is still loading it returns `undefined`. */ get values(): S | undefined; /** * The values the form was initialized with. */ get initialValues(): Partial; get pristine(): boolean; get dirty(): boolean; get submitting(): boolean; get valid(): boolean; /** * Resets the values back to the initial values the form was initialized with. * Or empties all the values if the form was not initialized. */ reset(): Promise; /** * @deprecated Unnecessary indirection */ updateFields(fields: F[]): void; /** * Subscribes to changes to the form. The subscriber will only be called when * values specified in subscription change. A form can have many subscribers. */ subscribe: FormApi['subscribe']; onSubmit: Config['onSubmit']; private handleSubmit; /** * Submits the form if there are currently no validation errors. It may * return undefined or a Promise depending on the nature of the onSubmit * configuration value given to the form when it was created. */ submit: FormApi['submit']; /** * Changes the value of the given field. * * @param name * @param value */ change(name: keyof S, value?: any): void; get mutators(): Record any>; /** * Updates multiple fields in the form. * * The updates are batched so that it only triggers one `onChange` event. * * In order to prevent disruptions to the user's editing experience this * function will _not_ update the value of any field that is currently * being edited. * * @param values */ updateValues(values: S): void; /** * Replaces the initialValues of the form without deleting the current values. * * This function is helpful when the initialValues are loaded asynchronously. * * @param initialValues */ updateInitialValues(initialValues: S): void; }