/** * DYNAMIC FORM UTILS: a collection of pure/mostly pure functions that are useful both internally and for * developing the consuming app. * * They are sorted by use case: building out the form object; helper functions to use with the showField function; * helper functions to use with the compute field function; and other logic shared between components */ import { SelectFieldConfig, SelectOption, AnyFieldConfig, FormConfig } from './models'; import { Observable } from 'rxjs'; import { FormGroup, FormArray, FormControl } from '@angular/forms'; import { AutocompleteFieldConfig } from './models'; /** * Required configuration to use with checkControlForValues function */ export interface CheckControlConfig { controlName: string; values: string[]; evaluate?: (isValueInValues: boolean) => boolean; } /** * Watches a single control for a list of values, returns true when field value matches any value in list * unless an evaluate method is found on config, in which case that method is run on the returned boolean value * @param group the direct parent of the field we want to watch * @param config */ export declare function checkControlForValues(group: FormGroup, config: CheckControlConfig): Observable; /** * The required configuration for running the checkControlsForValues function. */ export interface CheckControlsConfig { watchConfigs: CheckControlConfig[]; evaluate?: (bools: boolean[]) => boolean; } /** * Watches a list of fields for individual lists of values returning true when any field contains one * of the values being watched for, or optionally running a function on the array of resolved booleans * from the listed fields and returning a boolean * @param group the form group that has the fields to watch as direct descendants * @param config the configuration to use when calling the function */ export declare function checkControlsForValues(group: FormGroup, config: CheckControlsConfig): Observable; /** * The required configuration when running the computeValue function */ export interface ComputeFieldConfig { controlNameToSet?: string; controlNamesToWatch: string[]; computeCallback: (values: (string | number)[]) => string | number; } /** * Watches values on an array of fields, computing their values as they change * @param group the group to get the fields from, for now it can only be the parent of the computed field * @param computeFieldsConfig the configuration that drives the computation, holds the names to watch and the * computation function that get called against the array of values */ export declare function computeValueFromFields(group: FormGroup, computeFieldsConfig: ComputeFieldConfig): Observable; /** * The user can give us select options as an array, a function that resolves to a promise, * or an observable. This functions consumes any of those and returns an observable that * resolves an array of options * * @param options the options passed in from the config * @param emptyMessageOption the message to display when the array is empty */ export declare function observablifyOptions(config: SelectFieldConfig | AutocompleteFieldConfig, group?: FormGroup): Observable; /** * * @param config a configuration for a form group * @param value an object of initial values to pass in * @param group the form group to modify and build out */ export declare function buildFormGroupFromConfig(config: FormConfig, value?: any, group?: FormGroup): FormGroup; /** * Analyze the config and build a form control to spec. Notice we don't use FormBuilder here * as we want to keep this function pure. * @param controlConfig the configuration object for the control to build * @param value an initial value to use if passed in */ export declare function createControlForType(controlConfig: AnyFieldConfig, value: any): FormGroup | FormArray | FormControl;