-
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: add usnscribe from subscribe to form group changes, change trans…
…form class validator to usage async angular validator
- Loading branch information
1 parent
7de4189
commit 59270ba
Showing
11 changed files
with
165 additions
and
95 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
5 changes: 3 additions & 2 deletions
5
libs/ngx-dynamic-form-builder/src/lib/models/dynamic-form-group-field.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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { DynamicFormGroup } from '../utils/dynamic-form-group'; | ||
import { ValidationMetadata } from 'class-validator/metadata/ValidationMetadata'; | ||
import { DynamicFormGroup } from '../utils/dynamic-form-group'; | ||
import { ValidatorFunctionType } from './validator-function-type'; | ||
|
||
export interface DynamicFormGroupField { | ||
data: any | DynamicFormGroup<any>; | ||
validationFunctions: any[]; | ||
validationFunctions: ValidatorFunctionType[]; | ||
validationDefinitions: ValidationMetadata[]; | ||
} |
1 change: 1 addition & 0 deletions
1
libs/ngx-dynamic-form-builder/src/lib/models/error-property-name.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 @@ | ||
export type ErrorPropertyName = 'nestedValidate' | 'customValidation' | 'dynamicValidate'; |
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,5 @@ | ||
import { FormArray } from '@angular/forms'; | ||
import { DynamicFormGroup } from '../utils/dynamic-form-group'; | ||
|
||
// Enforces the properties of the object, if supplied, to be of the original type or DynamicFormGroup or, FormArray | ||
export type FormModel<T> = { [P in keyof T]?: T[P] | DynamicFormGroup<any> | FormArray }; |
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
libs/ngx-dynamic-form-builder/src/lib/models/validator-function-type.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,13 @@ | ||
import { AsyncValidatorFn, ValidatorFn } from '@angular/forms'; | ||
|
||
export interface ValidatorFunctionSyncType { | ||
type: 'sync'; | ||
validator: ValidatorFn; | ||
} | ||
|
||
export interface ValidatorFunctionAsyncType { | ||
type: 'async'; | ||
validator: AsyncValidatorFn; | ||
} | ||
|
||
export type ValidatorFunctionType = ValidatorFunctionSyncType | ValidatorFunctionAsyncType; |
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
16 changes: 12 additions & 4 deletions
16
libs/ngx-dynamic-form-builder/src/lib/utils/dynamic-form-control.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 |
---|---|---|
@@ -1,13 +1,21 @@ | ||
import { FormControl } from '@angular/forms'; | ||
import { DynamicFormGroupField } from '../models'; | ||
import { AsyncValidatorFn, FormControl, ValidatorFn } from '@angular/forms'; | ||
import { ValidationMetadata } from 'class-validator/metadata/ValidationMetadata'; | ||
import { Observable } from 'rxjs'; | ||
import { DynamicFormGroupField } from '../models/dynamic-form-group-field'; | ||
|
||
export class DynamicFormControl extends FormControl { | ||
public validationDefinitions: ValidationMetadata[]; | ||
|
||
constructor(fieldDefinition: DynamicFormGroupField) { | ||
super(fieldDefinition.data, fieldDefinition.validationFunctions); | ||
|
||
super( | ||
fieldDefinition.data instanceof Observable ? null : fieldDefinition.data, | ||
fieldDefinition.validationFunctions | ||
.filter(func => func.type === 'sync') | ||
.map(func => func.validator as ValidatorFn), | ||
fieldDefinition.validationFunctions | ||
.filter(func => func.type === 'async') | ||
.map(func => func.validator as AsyncValidatorFn) | ||
); | ||
this.validationDefinitions = fieldDefinition.validationDefinitions; | ||
} | ||
} |
Oops, something went wrong.