Skip to content

Commit

Permalink
feat(FormTouchOnHover): markFormGroupTouched() is now a static method ⚡
Browse files Browse the repository at this point in the history
  • Loading branch information
flauc committed Jun 27, 2018
1 parent 7133022 commit 260d689
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion projects/ng-helpers/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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();
}
}

0 comments on commit 260d689

Please sign in to comment.