-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update for correct support conditional validations
- Loading branch information
1 parent
9c738a9
commit 1c0e744
Showing
10 changed files
with
163 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
26 changes: 26 additions & 0 deletions
26
apps/demo/src/app/panels/exp-registration-panel/exp-registration-panel.component.html
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<form [formGroup]="form" *ngIf="form?.customValidateErrors | async as errors" novalidate> | ||
<h3>Group form</h3> | ||
<mat-form-field class="full-width"> | ||
<input matInput formControlName="username" placeholder="Username" /> | ||
<mat-error *ngIf="errors?.username?.length">{{ (errors?.username)[0] }}</mat-error> | ||
</mat-form-field> | ||
<mat-form-field class="full-width"> | ||
<input matInput type="password" formControlName="password" placeholder="Password" /> | ||
<mat-error *ngIf="errors?.password?.length">{{ (errors?.password)[0] }}</mat-error> | ||
</mat-form-field> | ||
<mat-form-field class="full-width"> | ||
<input matInput type="password" formControlName="rePassword" placeholder="Confirm password" /> | ||
<mat-error *ngIf="errors?.rePassword?.length">{{ (errors?.rePassword)[0] }}</mat-error> | ||
</mat-form-field> | ||
<div class="full-width"> | ||
<p>Form status: {{ form.status | json }}</p> | ||
<p>Form class-validator errors: {{ errors | json }}</p> | ||
<p>Form native errors: {{ form?.nativeValidateErrors | async | json }}</p> | ||
<p *ngIf="savedItem">Registration user data: {{ savedItem | json }}</p> | ||
</div> | ||
<div class="full-width"> | ||
<button mat-raised-button (click)="onRegistrationClick()" [disabled]="!form.valid" cdkFocusInitial> | ||
Registration | ||
</button> | ||
</div> | ||
</form> |
35 changes: 35 additions & 0 deletions
35
apps/demo/src/app/panels/exp-registration-panel/exp-registration-panel.component.ts
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core'; | ||
import { DynamicFormBuilder, DynamicFormGroup } from 'ngx-dynamic-form-builder'; | ||
import { ExpUser } from '../../shared/models/exp-user'; | ||
|
||
@Component({ | ||
selector: 'exp-registration-panel', | ||
templateUrl: './exp-registration-panel.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class ExpRegistrationPanelComponent implements OnInit { | ||
form: DynamicFormGroup<ExpUser>; | ||
|
||
fb = new DynamicFormBuilder(); | ||
|
||
savedItem?: ExpUser; | ||
|
||
constructor() { | ||
this.form = this.fb.group(ExpUser, { | ||
customValidatorOptions: { | ||
groups: ['new'] | ||
} | ||
}); | ||
} | ||
ngOnInit() { | ||
this.savedItem = undefined; | ||
this.form.object = new ExpUser(); | ||
this.form.validateAllFormFields(); | ||
} | ||
onRegistrationClick(): void { | ||
this.form.validateAllFormFields(); | ||
if (this.form.valid) { | ||
this.savedItem = this.form.object; | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
apps/demo/src/app/panels/exp-registration-panel/exp-registration-panel.module.ts
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { FlexLayoutModule } from '@angular/flex-layout'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { ModuleWithProviders } from '@angular/core'; | ||
import { ExpRegistrationPanelComponent } from '../exp-registration-panel/exp-registration-panel.component'; | ||
import { ReactiveFormsModule, FormsModule } from '@angular/forms'; | ||
import { SharedModule } from '../../shared/shared.module'; | ||
import { MatInputModule } from '@angular/material/input'; | ||
import { MatCheckboxModule } from '@angular/material/checkbox'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
SharedModule.forRoot(), | ||
MatButtonModule, | ||
MatInputModule, | ||
MatCheckboxModule, | ||
FormsModule, | ||
ReactiveFormsModule, | ||
FlexLayoutModule | ||
], | ||
entryComponents: [ExpRegistrationPanelComponent], | ||
exports: [ExpRegistrationPanelComponent], | ||
declarations: [ExpRegistrationPanelComponent] | ||
}) | ||
export class ExpRegistrationPanelModule { | ||
static forRoot(): ModuleWithProviders { | ||
return { | ||
ngModule: ExpRegistrationPanelModule, | ||
providers: [] | ||
}; | ||
} | ||
} |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters