import { default as DynamicElement } from './DynamicElement'; import { FormConfiguration, FormBehavior, UpdateRule } from './FormConfigurationTypes'; import { Observer, Subject } from './ObserverPatternTypes'; /** * This class represents a form with dynamic content, e.g. select with variable options, updating rules and visibility depending on fields' state... */ declare class DynamicForm implements Subject { /** @param {string} id - the form id */ readonly id: string; /** @param {boolean} debug - a flag to enable debug mode */ debug: boolean; /** @param {FormBehavior} behavior - object which groups some properties related to form behavior */ behavior: FormBehavior; /** @param {Map} fields - a collection of form's DynamicElements instances */ fieldsMap: Map; /** @param {Map; /** @param {FormConfiguration} config - the original form configuration */ config: FormConfiguration; /** @param {HTMLFormElement} HTMLFormElement - the actual html element returned by getElementById */ readonly htmlElement: HTMLFormElement; /** @param {boolean} enabled - a flag to enable/disable the Dynamic Form */ enabled: boolean; /** @param {Promise} initPromise - promise fulfilled when dynamicform initialisation is complete */ initPromise: Promise; /** * Class constructor. * @param {object} formConfiguration the form configuration in JSON format */ constructor(formHtmlElement: HTMLFormElement, formConfiguration: FormConfiguration, fieldsMap: Map); private createFieldUpdateRulesMap; private handleInitialisation; private initialiseFields; /** * Method used to understand when the dynamic-form initialisation is completed * @returns {Promise} promise resolved when initialisation is completed */ ready(): Promise; attach(observer: Observer): void; /** * Method to notify the change of the subject to all its observers (Observer Design Pattern). * @param {string} subjectName the name of the field who changed * @returns {Promise} promise resolved when all updates are completed */ notify(subjectName: string): Promise; /** * Method to retrieve all parameter required for a remote call according to a form update rule. * @param {UpdateRule} rule a specific form update rule * @return an object merging sender data and additional data */ private fetchAllParameters; /** * Method to clear fields on cascade when the subject changes. * The fields cleared are the subjects'observers'observers. * This implementation uses the DFS algorithm. * @param {string} currentSubject node name whom observers will be cleared * @param {array} visited array of already cleared (visited) nodes */ private clearCascade; /** * Method to manual trigger the update function of a subject. * @param {object} data data useful to the element's status change * @param {string} subjectName name of the changed subject * @returns a Promise in fulfilled state when element status has been updated */ manualUpdate(data: object, subjectName: string): Promise; /** * Method to fetch a single dynamic field instance * @param {string} name name of dynamic field instance to retrieve * @returns the DynamicElement instance */ private getField; /** * Return form's id * @return {string} the form id */ getId(): string; /** * Method to enable/disable the form update * @param {boolean} enable true to enable the form update, false otherwise */ setEnabled(enable: boolean): void; /** * Method to know if the form update is currently enabled * @return {boolean} true if the form is currently enabled, false otherwise */ isEnabled(): boolean; } export default DynamicForm;