-
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.
feat(dynamic-form-builder): Add support use ValidatorOptions
Example: ``` this.form = this.fb.group(ExpUser, undefined, { customValidatorOptions: { groups: ['user'] } }); ```
- Loading branch information
1 parent
c684fcd
commit 57ac15a
Showing
12 changed files
with
986 additions
and
471 deletions.
There are no files selected for viewing
18 changes: 12 additions & 6 deletions
18
apps/demo/src/app/pages/experimental-page/experimental-page.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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
<div class="experimental-page" fxLayout.gt-md="row" fxLayout.lt-md="column" fxLayoutAlign="space-evenly stretch"> | ||
<ngx-docs-example title="Experimental: user panel" [html]="source.html" [ts]="source.ts" [launch]="source.launch" fxFlex.gt-sm="50" | ||
fxFlex.lt-sm="100"> | ||
<div class="body"> | ||
<exp-user-panel></exp-user-panel> | ||
</div> | ||
</ngx-docs-example> | ||
<div fxFlex.gt-sm="50" fxFlex.lt-sm="100"> | ||
<ngx-docs-example title="Experimental: user panel" [html]="source.html" [ts]="source.ts" [launch]="source.launch"> | ||
<div class="body"> | ||
<exp-user-panel></exp-user-panel> | ||
</div> | ||
</ngx-docs-example> | ||
<ngx-docs-example title="Experimental: login panel" [html]="loginSource.html" [ts]="loginSource.ts" [launch]="loginSource.launch"> | ||
<div class="body"> | ||
<exp-login-panel></exp-login-panel> | ||
</div> | ||
</ngx-docs-example> | ||
</div> | ||
<source-tabs title="Other files" [files]="otherFiles" fxFlex.gt-sm="50" fxFlex.lt-sm="100"></source-tabs> | ||
</div> |
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
18 changes: 18 additions & 0 deletions
18
apps/demo/src/app/panels/exp-login-panel/exp-login-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,18 @@ | ||
<form [formGroup]="form" novalidate> | ||
<h3>Group form</h3> | ||
<mat-form-field class="full-width"> | ||
<input matInput formControlName="username" placeholder="Username"> | ||
<mat-error *ngIf="(form?.customValidateErrors | async)?.username?.length"> | ||
{{(form?.customValidateErrors | async).username[0]}} | ||
</mat-error> | ||
</mat-form-field> | ||
<mat-form-field class="full-width"> | ||
<input matInput type="password" formControlName="password" placeholder="Password"> | ||
<mat-error *ngIf="(form?.customValidateErrors | async)?.password?.length"> | ||
{{(form.customValidateErrors | async).password[0]}} | ||
</mat-error> | ||
</mat-form-field> | ||
<div class="full-width"> | ||
<button mat-raised-button (click)="onLoginClick()" [disabled]="!form.valid" cdkFocusInitial>Login</button> | ||
</div> | ||
</form> |
39 changes: 39 additions & 0 deletions
39
apps/demo/src/app/panels/exp-login-panel/exp-login-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,39 @@ | ||
import { DynamicFormGroup, DynamicFormBuilder } from 'ngx-dynamic-form-builder'; | ||
import { Company } from './../../shared/models/company'; | ||
import { Department } from '../../shared/models/department'; | ||
import { ExpUser } from '../../shared/models/exp-user'; | ||
import { Input, Component, OnInit } from '@angular/core'; | ||
import { Validators } from '@angular/forms'; | ||
|
||
@Component({ | ||
selector: 'exp-login-panel', | ||
templateUrl: './exp-login-panel.component.html' | ||
}) | ||
export class ExpLoginPanelComponent implements OnInit { | ||
|
||
@Input() | ||
form: DynamicFormGroup<ExpUser>; | ||
|
||
fb = new DynamicFormBuilder(); | ||
savedItem: ExpUser; | ||
|
||
constructor() { | ||
this.form = this.fb.group(ExpUser, undefined, { | ||
customValidatorOptions: { | ||
groups: ['guest'] | ||
} | ||
}); | ||
} | ||
ngOnInit() { | ||
this.savedItem = undefined; | ||
this.form.object = new ExpUser(); | ||
this.form.validateAllFormFields(); | ||
} | ||
onLoginClick(): void { | ||
if (this.form.valid) { | ||
this.savedItem = this.form.object; | ||
} else { | ||
this.form.validateAllFormFields(); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
apps/demo/src/app/panels/exp-login-panel/exp-login-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,31 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { FlexLayoutModule } from '@angular/flex-layout'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { ModuleWithProviders } from '@angular/core'; | ||
import { ExpLoginPanelComponent } from '../../panels/exp-login-panel/exp-login-panel.component'; | ||
import { MatInputModule, MatCheckboxModule } from '@angular/material'; | ||
import { ReactiveFormsModule, FormsModule } from '@angular/forms'; | ||
import { SharedModule } from '../../shared/shared.module'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
SharedModule.forRoot(), | ||
MatButtonModule, | ||
MatInputModule, | ||
MatCheckboxModule, | ||
FormsModule, | ||
ReactiveFormsModule, | ||
FlexLayoutModule | ||
], | ||
entryComponents: [ExpLoginPanelComponent], | ||
exports: [ExpLoginPanelComponent], | ||
declarations: [ExpLoginPanelComponent] | ||
}) | ||
export class ExpLoginPanelModule { | ||
static forRoot(): ModuleWithProviders { | ||
return { | ||
ngModule: ExpLoginPanelModule, | ||
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
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
Oops, something went wrong.