@eponacon/utils-form-group-lib
Version:
Methods to help validate and manipulate the material form group
64 lines (59 loc) • 2.83 kB
JavaScript
import * as i0 from '@angular/core';
import { Injectable, NgModule } from '@angular/core';
class UtilsFormGroupLibService {
constructor() { }
validateFormGroup(form) {
let validField = true;
Object.entries(form.controls).forEach(([, val]) => {
let valItemForm = val;
if (valItemForm.status == 'INVALID') {
validField = false;
valItemForm.markAsTouched();
}
});
return validField;
}
insertValuesFormGroup(dataObject, form) {
try {
Object.entries(dataObject).forEach(([key, val]) => {
if (!form.controls[`${key}`])
return;
if (typeof val === 'boolean') {
form.controls[`${key}`].setValue(val);
}
else {
form.controls[`${key}`].setValue(`${val !== null ? val : ''}`);
}
});
}
catch (error) {
console.warn('Error insert data fom form group');
}
}
}
UtilsFormGroupLibService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0, type: UtilsFormGroupLibService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
UtilsFormGroupLibService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0, type: UtilsFormGroupLibService, providedIn: 'root' });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0, type: UtilsFormGroupLibService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root',
}]
}], ctorParameters: function () { return []; } });
class UtilsFormGroupLibModule {
}
UtilsFormGroupLibModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0, type: UtilsFormGroupLibModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
UtilsFormGroupLibModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0, type: UtilsFormGroupLibModule });
UtilsFormGroupLibModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0, type: UtilsFormGroupLibModule, imports: [[]] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0, type: UtilsFormGroupLibModule, decorators: [{
type: NgModule,
args: [{
declarations: [],
imports: [],
exports: [],
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { UtilsFormGroupLibModule, UtilsFormGroupLibService };
//# sourceMappingURL=eponacon-utils-form-group-lib.js.map