### File

`projects/commons/src/lib/core/form/abstracts/form.ts`

### Implements

`OnInit`

### Index

###### Properties
Public errorMessage Public form Public isLoading Public isSubmitted
###### Methods
Protected addFormValidator Protected getRawValue Public ngOnInit

### Constructor

`constructor(schema: Data, formBuilder: FormBuilder)`
Defined in projects/commons/src/lib/core/form/abstracts/form.ts:9
Parameters :
Name | Type | Optional
schema | `Data` | No
formBuilder | `FormBuilder` | No

### Properties

Public errorMessage
Type : `string`
Defined in projects/commons/src/lib/core/form/abstracts/form.ts:9

Public form
Type : `FormGroup`
Defined in projects/commons/src/lib/core/form/abstracts/form.ts:6

Public isLoading
Type : `boolean`
Defined in projects/commons/src/lib/core/form/abstracts/form.ts:7

Public isSubmitted
Type : `boolean`
Defined in projects/commons/src/lib/core/form/abstracts/form.ts:8

### Methods

Protected addFormValidator
`addFormValidator(name: string, validators: Validators, value: string)`
Defined in projects/commons/src/lib/core/form/abstracts/form.ts:31
Parameters :
Name | Type | Optional | Default value
name | `string` | No |
validators | `Validators` | No |
value | `string` | No | `''`
Returns : `void`

Protected getRawValue
`getRawValue()`
Defined in projects/commons/src/lib/core/form/abstracts/form.ts:20
Returns : `any`

Public ngOnInit
`ngOnInit()`
Defined in projects/commons/src/lib/core/form/abstracts/form.ts:16
Returns : `void`

    import { Data } from '@angular/router';
    import { OnInit } from '@angular/core';
    import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';

    export abstract class Form implements OnInit {
        public form: FormGroup;
        public isLoading: boolean;
        public isSubmitted: boolean;
        public errorMessage: string;

        constructor(
            private readonly schema: Data,
            private readonly formBuilder: FormBuilder,
        ) {}

        public ngOnInit(): void {
            this.form = this.formBuilder.group(this.schema);
        }

        protected getRawValue() {
            this.isLoading = true;
            this.errorMessage = '';

            if (this.form.valid) {
                return this.form.getRawValue();
            } else {
                this.isSubmitted = true;
            }
        }

        protected addFormValidator(name: string, validators: Validators, value: string = '') {
            this.form.addControl(name, new FormControl(value, validators));
        }
    }

# result-matching ""

# No results matching ""