Skip to content

Commit 248ddb8

Browse files
committed
docs: add context clearing example
1 parent 616681a commit 248ddb8

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/app/lazy/lazy-form/lazy-form.component.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11

2-
<div style="width: 40%; text-align: center;margin: auto">
3-
<img src="assets/images/logo-blu.svg"/>
4-
</div>
5-
<h2 style="text-align: center">xtream validation errors lazy</h2>
6-
<form [formGroup]="heroForm" validationContext="NEW_HERO" innerValidationError="true">
2+
<form [formGroup]="heroForm" #firstForm validationContext="NEW_HERO" innerValidationError="true">
73
<div formFieldContainer class="input-wrapper form-group">
84
<label>Name</label>
95
<input class="form-control" formControlName="name"/>
@@ -21,7 +17,8 @@ <h2 style="text-align: center">xtream validation errors lazy</h2>
2117
</div>
2218
</div>
2319

24-
<button class="btn btn-primary" [disabled]="heroForm.invalid">Submit</button>
20+
<button class="btn btn-primary" [disabled]="heroForm.invalid" style="margin-right: 15px">Submit</button>
21+
<button class="btn btn-secondary" (click)="clearForm()">Clear</button>
2522

2623
</form>
2724

src/app/lazy/lazy-form/lazy-form.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import {Component, OnInit} from '@angular/core';
1+
import {Component, OnInit, ViewChild} from '@angular/core';
22
import {AbstractControl, FormArray, FormControl, FormGroup, Validators} from '@angular/forms';
33
import {TranslateService} from '@ngx-translate/core';
4+
import {ValidationContextComponent} from '@xtream/ngx-validation-errors';
45

56
function minCheckSelected(size: number) {
67
return (control: AbstractControl) => {
@@ -20,6 +21,8 @@ function minCheckSelected(size: number) {
2021
})
2122
export class LazyFormComponent implements OnInit {
2223

24+
@ViewChild('firstForm', {read: ValidationContextComponent}) validationContext: ValidationContextComponent;
25+
2326
heroForm: FormGroup;
2427

2528
boxesInfo = [
@@ -41,4 +44,10 @@ export class LazyFormComponent implements OnInit {
4144
this.translateService.setDefaultLang('en');
4245
this.translateService.use('en');
4346
}
47+
48+
clearForm() {
49+
console.debug('this.validationContext', this.validationContext);
50+
this.validationContext.clear();
51+
52+
}
4453
}

0 commit comments

Comments
 (0)