### File

`packages/eui-dynamic-forms-ui/src/lib/shared/services/form-api-service.ts`

### Index

###### Properties

- Public isReady
- Public unsubscribe$

###### Methods

- clearErrors
- getCustomData
- getFieldData
- getFieldDataEvent
- getFormModel
- getFormModelChanges
- getFormMultiStore
- getFormState
- getFrameId
- getInitialData
- getMetaData
- getMode
- getParentFormGroup
- patchFormValue
- pubEvent
- runValidationErrorFeedbacks
- saveCustomData
- saveFieldData
- setErrors
- setMode
- stopSubscriptions
- subEvent
- updateMetaData

### Constructor

`constructor(data: FormConstructor | FormSelector)`

Parameters :

Name | Type | Optional
data | `FormConstructor | FormSelector` | No

### Properties

Public isReady
Default value : `new BehaviorSubject<boolean>(false)`

Public unsubscribe$
Type : `Subject<boolean>`
Default value : `new Subject<boolean>()`

### Methods

clearErrors
`clearErrors()`
Setting errors by respecting formModel object structure, It is usefule to provide the server side validations to form instance/view. Returns : `void`

getCustomData
`getCustomData(key: string)`

Every form Instance has its state and customData property in that state. This method is subscribing to your instance's customData state's sub state by 'key' that you provide After you called saveCustomData('your_key',yourData) getCustomData('your_key').subscribe((newData)=> //subscription will be triggered , and newData will be yourData )

Parameters :

Name | Type | Optional
key | `string` | No

Returns : `Observable<any>`

getFieldData
`getFieldData(fieldId: UxFieldId, key: string, levelId?: string)`

By this method, you can get custom data with key pair from the field's state. Every field has a fieldId( automatically generated or defined into generator function) and has a sub-state on the NGRX_state->form_frameId->fieldData->fieldId->key1:data1,key2:data2... note:this method is used by BaseDynComponent (and by BaseControl-Group-Array classes that extends BaseDynComponent class) from every field that you extended base-classes, you can use this.getFieldData(key) helper method without defining frameId or fieldId

Parameters :

Name | Type | Optional
fieldId | `UxFieldId` | No
key | `string` | No
levelId | `string` | Yes

Returns : `Observable<any>`

getFieldDataEvent
`getFieldDataEvent(fieldId: UxFieldId, key: string)`

By this method, you can listen fieldData events for a particular fieldId

Parameters :

Name | Type | Optional
fieldId | `UxFieldId` | No
key | `string` | No

Returns : `Observable<SaveFieldDataEvent>`

getFormModel
`getFormModel()`
Returns latest state of the formModel. When user interact with inputs, latest changes will reflect to the formModel Returns : `any`

getFormModelChanges
`getFormModelChanges()`
Returns latest state of the formModel. When user interact with inputs, latest changes will reflect to the formModel Returns : `Observable<any>`

getFormMultiStore
`getFormMultiStore()`
Returns instance's isolated Store ,as instance of IsolatedMultiReduxHelper that you can dispatch actions or select by selector function on it. the actions and selectors will be working in the same scope of your instance(frameId). Returns : `IsolatedMultiReduxHelper`

getFormState
`getFormState()`
Returns subscription(selector) of Its isolated formState that is sub-selection by its frameId from global State.(form+frameId) Whenever instance's formState change, this selection subscription will be triggered. Returns : `Observable<FormState>`

getFrameId
`getFrameId()`
Returns the generated or defined frameId of the DynFormApi instance Returns : `string`

getInitialData
`getInitialData()`
Returns passed initialData Returns : `any`

getMetaData
`getMetaData()`
Returns the passed MetaData Returns : `UxDynFormModelArray`

getMode
`getMode()`
Returns Forms's mode edit/view ->FormModes Returns : `Observable<FormModes>`

getParentFormGroup
`getParentFormGroup()`
Returns Angular's FormGroup instance's root of your form. It will generate form tree based on the structure of your metaData and It is free to access/use its methods and properties in native way. Returns : `FormGroup`

patchFormValue
`patchFormValue(newData)`

Whenever this method runs, It updates formModel like you provided initialValues (by emitting event). getParentFormGroup() is returning FormGroup, and its patchValue() function could be used for custom scenarios.

Parameters :

Name | Optional
newData | No

Returns : `void`

pubEvent
`pubEvent(evt)`

To publish custom/default events inside your form instance. (PUB/SUB) DynFormApi is using this method to publish Life Cycle Event like FormModelReady

Parameters :

Name | Optional
evt | No

Returns : `void`

runValidationErrorFeedbacks
`runValidationErrorFeedbacks(controlSet?: FormGroup | FormArray)`

Marks as touched and sets errors for provided form-group/control ancestors If It is not provided, It is root group.

Parameters :

Name | Type | Optional
controlSet | `FormGroup | FormArray` | Yes

Returns : `void`

saveCustomData
`saveCustomData(key: string, data: any)`

Every form Instance has its state and customData property in that state. This method is saving your 'data' to customData state by respecting the 'key' that you provide

Parameters :

Name | Type | Optional
key | `string` | No
data | `any` | No

Returns : `void`

saveFieldData
`saveFieldData(fieldId: UxFieldId, key: string, data: any, levelId?: string, interpreted?: boolean)`

By this method, you can save custom key:data pair for the field itself. Every field has a fieldId( automatically generated or defined into generator function) and has a sub-state on the NGRX_state->form_frameId->fieldData->fieldId->key1:data1,key2:data2... note:this method is used by BaseDynComponent (and by BaseControl-Group-Array classes that extends BaseDynComponent class) from every field that you extended base-classes, you can use this.saveFieldData(key,val) helper method without defining frameId or fieldId

Parameters :

Name | Type | Optional
fieldId | `UxFieldId` | No
key | `string` | No
data | `any` | No
levelId | `string` | Yes
interpreted | `boolean` | Yes

Returns : `void`

setErrors
`setErrors(object, options?: literal type)`

Setting errors by respecting formModel object structure, It is usefule to provide the server side validations to form instance/view.

Parameters :

Name | Type | Optional
object |  | No
options | `literal type` | Yes

Returns : `void`

setMode
`setMode(newMode: FormModes)`

Sets the mode as edit or view

Parameters :

Name | Type | Optional
newMode | `FormModes` | No

Returns : `void`

stopSubscriptions
`stopSubscriptions()`
Kills all the subscription attached to the FormApi instance Returns : `void`

subEvent
`subEvent()`
Returns subscribtion to the custom/default events that published for your formInstance. This method is accessible from custom components/fields that you implemented. You can use this communication layer for inter-component interactions/behaviours Returns : `Observable<any>`

updateMetaData
`updateMetaData(newMetaData: UxDynFormModelArray)`

This method accepts new metadata and updates to the Form Instance by assuming latest state as new initial data.

Parameters :

Name | Type | Optional
newMetaData | `UxDynFormModelArray` | No

Returns : `void`

# result-matching ""

# No results matching ""