@ng-formworks/core
Version:
Angular ng-formworks - JSON Schema Form builder core
127 lines (126 loc) • 4.6 kB
TypeScript
import { AbstractControl } from '@angular/forms';
import { Pointer } from './jsonpointer.functions';
/**
* path2ControlKey takes a datapointer path like /some/pointer/path
* and returns something like $some$pointer$path
* used mainly to convert paths so it can be used as keys in FormGroups
* fot ITE scenarios
* @param path
* @returns string
*/
export declare function path2ControlKey(path: string): string;
/**
* FormGroup function library:
*
* buildFormGroupTemplate: Builds a FormGroupTemplate from schema
*
* buildFormGroup: Builds an Angular FormGroup from a FormGroupTemplate
*
* mergeValues:
*
* setRequiredFields:
*
* formatFormData:
*
* getControl:
*
* ---- TODO: ----
* TODO: add buildFormGroupTemplateFromLayout function
* buildFormGroupTemplateFromLayout: Builds a FormGroupTemplate from a form layout
*/
/**
* 'buildFormGroupTemplate' function
*
* Builds a template for an Angular FormGroup from a JSON Schema.
*
* TODO: add support for pattern properties
* https://spacetelescope.github.io/understanding-json-schema/reference/object.html
*
* // {any} jsf -
* // {any = null} nodeValue -
* // {boolean = true} mapArrays -
* // {string = ''} schemaPointer -
* // {string = ''} dataPointer -
* // {any = ''} templatePointer -
* // {any} -
*/
export declare function buildFormGroupTemplate(jsf: any, nodeValue?: any, setValues?: boolean, schemaPointer?: string, dataPointer?: string, templatePointer?: string): {
controlType: string;
controls: any;
validators: any;
value?: undefined;
} | {
controlType: string;
value: {
value: any;
disabled: any;
};
validators: any;
controls?: undefined;
};
/**
* 'buildFormGroup' function
*
* // {any} template -
* // {AbstractControl}
*/
export declare function buildFormGroup(template: any): AbstractControl;
/**
* 'mergeValues' function
*
* // {any[]} ...valuesToMerge - Multiple values to merge
* // {any} - Merged values
*/
export declare function mergeValues(...valuesToMerge: any[]): any;
/**
* 'setRequiredFields' function
*
* // {schema} schema - JSON Schema
* // {object} formControlTemplate - Form Control Template object
* // {boolean} - true if any fields have been set to required, false if not
*/
export declare function setRequiredFields(schema: any, formControlTemplate: any): boolean;
/**
* 'formatFormData' function
*
* // {any} formData - Angular FormGroup data object
* // {Map<string, any>} dataMap -
* // {Map<string, string>} recursiveRefMap -
* // {Map<string, number>} arrayMap -
* // {boolean = false} fixErrors - if TRUE, tries to fix data
* // {any} - formatted data object
*/
export declare function formatFormData(formData: any, dataMap: Map<string, any>, recursiveRefMap: Map<string, string>, arrayMap: Map<string, number>, returnEmptyFields?: boolean, fixErrors?: boolean): any;
/**
* 'getControl' function
*
* Uses a JSON Pointer for a data object to retrieve a control from
* an Angular formGroup or formGroup template. (Note: though a formGroup
* template is much simpler, its basic structure is idential to a formGroup).
*
* If the optional third parameter 'returnGroup' is set to TRUE, the group
* containing the control is returned, rather than the control itself.
*
* // {FormGroup} formGroup - Angular FormGroup to get value from
* // {Pointer} dataPointer - JSON Pointer (string or array)
* // {boolean = false} returnGroup - If true, return group containing control
* // {group} - Located value (or null, if no control found)
* // {string} schemaPointer - string used for conditional controls coming from schema if/then/else
*/
export declare function getControl(formGroup: any, dataPointer: Pointer, returnGroup?: boolean, schemaPointer?: string): any;
/**
* 'setControl' function
*
* Uses a JSON Pointer for a data object to retrieve a control from
* an Angular formGroup or formGroup template. (Note: though a formGroup
* template is much simpler, its basic structure is idential to a formGroup).
*
* If the optional third parameter 'returnGroup' is set to TRUE, the group
* containing the control is returned, rather than the control itself.
*
* // {FormGroup} formGroup - Angular FormGroup to get value from
* // {Pointer} dataPointer - JSON Pointer (string or array)
* // {AbstractControl} control - control used to replace existing or add
* // {targetKey} - optional string used as the new key-not implemented as yet
*/
export declare function setControl(formGroup: any, dataPointer: Pointer, control: AbstractControl, targetKey?: string): any;