Forked from domagoj03/get-form-validation-errors.ts
Created
June 6, 2024 13:51
Revisions
-
domagoj03 revised this gist
Oct 14, 2019 . 1 changed file with 12 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,19 @@ import {FormGroup, ValidationErrors} from '@angular/forms'; export interface IFormError { control: string; error: string; value: any; } export function getFormValidationErrors(form: FormGroup) { const result = []; Object.keys(form.controls).forEach(key => { const formProperty = form.get(key); if (formProperty instanceof FormGroup) { result.push(...getFormValidationErrors(formProperty)) } const controlErrors: ValidationErrors = formProperty.errors; if (controlErrors) { Object.keys(controlErrors).forEach(keyError => { result.push({ -
JohannesHoppe revised this gist
Jul 19, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ export function getFormValidationErrors(form: FormGroup) { if (controlErrors) { Object.keys(controlErrors).forEach(keyError => { result.push({ 'control': key, 'error': keyError, 'value': controlErrors[keyError] }); -
JohannesHoppe renamed this gist
May 30, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
JohannesHoppe created this gist
May 30, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ import { FormGroup, ValidationErrors } from '@angular/forms'; export function getFormValidationErrors(form: FormGroup) { const result = []; Object.keys(form.controls).forEach(key => { const controlErrors: ValidationErrors = form.get(key).errors; if (controlErrors) { Object.keys(controlErrors).forEach(keyError => { result.push({ 'control ': key, 'error': keyError, 'value': controlErrors[keyError] }); }); } }); return result; }