From 260d6899b7f045a122e4299233ce18dfb28f0536 Mon Sep 17 00:00:00 2001 From: Filip Lauc Date: Wed, 27 Jun 2018 07:56:42 +0200 Subject: [PATCH] feat(FormTouchOnHover): markFormGroupTouched() is now a static method :zap: --- projects/ng-helpers/package.json | 2 +- .../form-touch-on-hover.directive.ts | 33 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/projects/ng-helpers/package.json b/projects/ng-helpers/package.json index 424b4c9..f7bd90a 100644 --- a/projects/ng-helpers/package.json +++ b/projects/ng-helpers/package.json @@ -1,6 +1,6 @@ { "name": "@jaspero/ng-helpers", - "version": "0.0.5", + "version": "0.0.6", "peerDependencies": { "@angular/common": "^6.0.0", "@angular/core": "^6.0.0" diff --git a/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.directive.ts b/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.directive.ts index c384a8e..f7520f2 100644 --- a/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.directive.ts +++ b/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.directive.ts @@ -6,29 +6,14 @@ import {FormGroup, FormArray} from '@angular/forms'; }) export class FormTouchOnHoverDirective { - /** - * Entry FormGroup which to iterate over - */ - @Input() jpFormTouchOnHover: FormGroup | FormArray; - - /** - * Outputs when form finish iterating - */ - @Output() jpFormTouched = new EventEmitter(); - - @HostListener('mouseenter') - enter() { - this._markFormGroupTouched(this.jpFormTouchOnHover); - } - - private _markFormGroupTouched(formGroup: (FormGroup | FormArray)) { + static markFormGroupTouched(formGroup: (FormGroup | FormArray)) { (Object as any).values(formGroup.controls) .forEach(control => { control.markAsTouched(); if (control && control.controls) { if (Array.isArray(control.controls)) { - control.controls.forEach(c => this._markFormGroupTouched(c)); + control.controls.forEach(c => FormTouchOnHoverDirective.markFormGroupTouched(c)); } else { for (const key in control.controls) { if (control.controls.hasOwnProperty(key)) { @@ -38,7 +23,21 @@ export class FormTouchOnHoverDirective { } } }); + } + /** + * Entry FormGroup which to iterate over + */ + @Input() jpFormTouchOnHover: FormGroup | FormArray; + + /** + * Outputs when form finish iterating + */ + @Output() jpFormTouched = new EventEmitter(); + + @HostListener('mouseenter') + enter() { + FormTouchOnHoverDirective.markFormGroupTouched(this.jpFormTouchOnHover); this.jpFormTouched.emit(); } }