validator fixes
This commit is contained in:
parent
951f34e0cc
commit
c7a3b58019
|
@ -44,7 +44,7 @@ export class DescriptionTemplateTypeEditorModel extends BaseEditorModel implemen
|
|||
const baseContext: ValidationContext = new ValidationContext();
|
||||
const baseValidationArray: Validation[] = new Array<Validation>();
|
||||
baseValidationArray.push({ key: 'id', validators: [BackendErrorValidator(this.validationErrorModel, 'id')] });
|
||||
baseValidationArray.push({ key: 'name', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'RenameourceId')] });
|
||||
baseValidationArray.push({ key: 'name', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'name')] });
|
||||
baseValidationArray.push({ key: 'status', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'status')] });
|
||||
baseValidationArray.push({ key: 'hash', validators: [] });
|
||||
|
||||
|
|
|
@ -35,10 +35,8 @@
|
|||
<mat-form-field class="col-lg-6">
|
||||
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.NAME' | translate}}</mat-label>
|
||||
<input matInput type="text" name="name" [formControl]="formGroup.get('name')" required>
|
||||
<mat-error *ngIf="formGroup.get('name').hasError('backendError')">
|
||||
{{formGroup.get('name').getError('backendError').message}}</mat-error>
|
||||
<mat-error *ngIf="formGroup.get('name').hasError('required')">
|
||||
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
<mat-error *ngIf="formGroup.get('name').hasError('backendError')">{{formGroup.get('name').getError('backendError').message}}</mat-error>
|
||||
<mat-error *ngIf="formGroup.get('name').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div class="info-grid-value">
|
||||
|
@ -89,24 +87,24 @@
|
|||
<mat-form-field class="w-100">
|
||||
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.LABEL' | translate}}</mat-label>
|
||||
<input matInput type="text" name="label" [formControl]="field.get('label')" required>
|
||||
<mat-error *ngIf="field.get('label').hasError('required')">
|
||||
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
<mat-error *ngIf="field.get('label').hasError('backendError')">{{field.get('label').getError('backendError').message}}</mat-error>
|
||||
<mat-error *ngIf="field.get('label').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<mat-form-field class="w-100">
|
||||
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.DESCRIPTION' | translate}}</mat-label>
|
||||
<input matInput type="text" name="description" [formControl]="field.get('description')">
|
||||
<mat-error *ngIf="field.get('description').hasError('required')">
|
||||
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
<mat-error *ngIf="field.get('description').hasError('backendError')">{{field.get('description').getError('backendError').message}}</mat-error>
|
||||
<mat-error *ngIf="field.get('description').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<mat-form-field class="w-100">
|
||||
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
|
||||
<input matInput type="text" name="code" [formControl]="field.get('code')" required>
|
||||
<mat-error *ngIf="field.get('code').hasError('required')">
|
||||
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
<mat-error *ngIf="field.get('code').hasError('backendError')">{{field.get('code').getError('backendError').message}}</mat-error>
|
||||
<mat-error *ngIf="field.get('code').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
|
|
|
@ -13,7 +13,7 @@ import { AppPermission } from '@app/core/common/enum/permission.enum';
|
|||
import { ReferenceFieldDataType } from '@app/core/common/enum/reference-field-data-type';
|
||||
import { ReferenceTypeExternalApiHTTPMethodType } from '@app/core/common/enum/reference-type-external-api-http-method-type';
|
||||
import { ReferenceTypeSourceType } from '@app/core/common/enum/reference-type-source-type';
|
||||
import { ReferenceType, ReferenceTypePersist } from '@app/core/model/reference-type/reference-type';
|
||||
import { ReferenceType, ReferenceTypeDefinition, ReferenceTypePersist } from '@app/core/model/reference-type/reference-type';
|
||||
import { AuthService } from '@app/core/services/auth/auth.service';
|
||||
import { LoggingService } from '@app/core/services/logging/logging-service';
|
||||
import { QueryParamsService } from '@app/core/services/utilities/query-params.service';
|
||||
|
@ -25,7 +25,7 @@ import { FilterService } from '@common/modules/text-filter/filter-service';
|
|||
import { Guid } from '@common/types/guid';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { map, takeUntil } from 'rxjs/operators';
|
||||
import { DependencyPropertyEditorModel, QueryConfigEditorModel, ReferenceTypeEditorModel, ReferenceTypeFieldEditorModel, ReferenceTypeSourceBaseConfigurationEditorModel, ReferenceTypeSourceBaseDependencyEditorModel, ReferenceTypeStaticOptionEditorModel, ResultFieldsMappingConfigurationEditorModel } from './reference-type-editor.model';
|
||||
import { DependencyPropertyEditorModel, QueryConfigEditorModel, ReferenceTypeDefinitionEditorModel, ReferenceTypeEditorModel, ReferenceTypeFieldEditorModel, ReferenceTypeSourceBaseConfigurationEditorModel, ReferenceTypeSourceBaseDependencyEditorModel, ReferenceTypeStaticOptionEditorModel, ResultFieldsMappingConfigurationEditorModel } from './reference-type-editor.model';
|
||||
import { ReferenceTypeEditorResolver } from './reference-type-editor.resolver';
|
||||
import { ReferenceTypeEditorService } from './reference-type-editor.service';
|
||||
|
||||
|
@ -172,9 +172,9 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
|
|||
|
||||
formSubmit(): void {
|
||||
this.formService.touchAllFormFields(this.formGroup);
|
||||
if (!this.isFormValid()) {
|
||||
return;
|
||||
}
|
||||
// if (!this.isFormValid()) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
this.persistEntity();
|
||||
}
|
||||
|
@ -213,8 +213,7 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
|
|||
//
|
||||
//
|
||||
addField(): void {
|
||||
const field: ReferenceTypeFieldEditorModel = new ReferenceTypeFieldEditorModel();
|
||||
(this.formGroup.get('definition').get('fields') as FormArray).push(field.buildForm());
|
||||
(this.formGroup.get('definition').get('fields') as FormArray).push(this.editorModel.createChildField((this.formGroup.get('definition').get('fields') as FormArray).length));
|
||||
}
|
||||
|
||||
removeField(fieldIndex: number): void {
|
||||
|
|
|
@ -2,7 +2,7 @@ import { UntypedFormBuilder, UntypedFormGroup, Validators } from "@angular/forms
|
|||
import { ReferenceFieldDataType } from "@app/core/common/enum/reference-field-data-type";
|
||||
import { ReferenceTypeExternalApiHTTPMethodType } from "@app/core/common/enum/reference-type-external-api-http-method-type";
|
||||
import { ReferenceTypeSourceType } from "@app/core/common/enum/reference-type-source-type";
|
||||
import { ReferenceType, ReferenceTypeDefinition, ReferenceTypeDefinitionPersist, ReferenceTypePersist, ReferenceTypeFieldPersist,ReferenceTypeField, AuthenticationConfiguration, AuthenticationConfigurationPersist, QueryConfigPersist, QueryConfig, ResultsConfigurationPersist, ResultFieldsMappingConfigurationPersist, ResultsConfiguration, ResultFieldsMappingConfiguration, ReferenceTypeSourceBaseConfigurationPersist, ReferenceTypeSourceBaseConfiguration, ReferenceTypeStaticOptionPersist, ReferenceTypeStaticOption, DependencyPropertyPersist, DependencyProperty, ReferenceTypeSourceBaseDependency, ReferenceTypeSourceBaseDependencyPersist } from "@app/core/model/reference-type/reference-type";
|
||||
import { AuthenticationConfiguration, AuthenticationConfigurationPersist, DependencyProperty, DependencyPropertyPersist, QueryConfig, QueryConfigPersist, ReferenceType, ReferenceTypeDefinition, ReferenceTypeDefinitionPersist, ReferenceTypeField, ReferenceTypeFieldPersist, ReferenceTypePersist, ReferenceTypeSourceBaseConfiguration, ReferenceTypeSourceBaseConfigurationPersist, ReferenceTypeSourceBaseDependency, ReferenceTypeSourceBaseDependencyPersist, ReferenceTypeStaticOption, ReferenceTypeStaticOptionPersist, ResultFieldsMappingConfiguration, ResultFieldsMappingConfigurationPersist, ResultsConfiguration, ResultsConfigurationPersist } from "@app/core/model/reference-type/reference-type";
|
||||
import { BaseEditorModel } from "@common/base/base-form-editor-model";
|
||||
import { BackendErrorValidator } from "@common/forms/validation/custom-validator";
|
||||
import { ValidationErrorModel } from "@common/forms/validation/error-model/validation-error-model";
|
||||
|
@ -58,6 +58,11 @@ export class ReferenceTypeEditorModel extends BaseEditorModel implements Referen
|
|||
baseContext.validation = baseValidationArray;
|
||||
return baseContext;
|
||||
}
|
||||
|
||||
createChildField(index: number): UntypedFormGroup {
|
||||
const field: ReferenceTypeFieldEditorModel = new ReferenceTypeFieldEditorModel(this.validationErrorModel);
|
||||
return field.buildForm({ rootPath: 'definition.fields[' + index + '].' });
|
||||
}
|
||||
}
|
||||
|
||||
export class ReferenceTypeDefinitionEditorModel implements ReferenceTypeDefinitionPersist {
|
||||
|
@ -97,7 +102,7 @@ export class ReferenceTypeDefinitionEditorModel implements ReferenceTypeDefiniti
|
|||
(item, index) => new ReferenceTypeFieldEditorModel(
|
||||
this.validationErrorModel
|
||||
).fromModel(item).buildForm({
|
||||
rootPath: `fields[${index}].`
|
||||
rootPath: `[${index}].`
|
||||
}), context.getValidation('fields')
|
||||
)
|
||||
),
|
||||
|
|
|
@ -23,8 +23,8 @@ export class ValidationErrorModel implements Serializable<ValidationErrorModel>
|
|||
let error: string;
|
||||
if (this.message && Array.isArray(this.message)) {
|
||||
for (const element of this.message) {
|
||||
if (element.Key === propertyName) {
|
||||
error = element.Value.join(', ');
|
||||
if (element.key === propertyName) {
|
||||
error = element.value.join(', ');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -38,10 +38,10 @@ export class ValidationErrorModel implements Serializable<ValidationErrorModel>
|
|||
const errors = new Map<number, string>();
|
||||
if (this.message && Array.isArray(this.message)) {
|
||||
this.message.forEach(element => {
|
||||
const match = element.Key.match(regExp);
|
||||
const match = element.key.match(regExp);
|
||||
if (match && match.length >= 2) {
|
||||
const index = Number.parseInt(match[1]);
|
||||
errors.set(index, element.Value.join(', '));
|
||||
errors.set(index, element.value.join(', '));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -52,15 +52,15 @@ export class ValidationErrorModel implements Serializable<ValidationErrorModel>
|
|||
if (this.message && Array.isArray(this.message)) {
|
||||
let exists = false;
|
||||
for (const element of this.message) {
|
||||
if (element.Key === propertyName) {
|
||||
if (!element.Value.includes(error)) { element.Value.push(error); }
|
||||
if (element.key === propertyName) {
|
||||
if (!element.value.includes(error)) { element.value.push(error); }
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exists) { this.message.push({ Key: propertyName, Value: [error] }); }
|
||||
if (!exists) { this.message.push({ key: propertyName, value: [error] }); }
|
||||
} else {
|
||||
this.message = [{ Key: propertyName, Value: [error] }];
|
||||
this.message = [{ key: propertyName, value: [error] }];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ export class ValidationErrorModel implements Serializable<ValidationErrorModel>
|
|||
this.error = undefined;
|
||||
if (this.message && Array.isArray(this.message)) {
|
||||
this.message.forEach(element => {
|
||||
element.Value.splice(0);
|
||||
element.value.splice(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -76,8 +76,8 @@ export class ValidationErrorModel implements Serializable<ValidationErrorModel>
|
|||
public clearPart(prefix: string) {
|
||||
if (this.message && Array.isArray(this.message)) {
|
||||
this.message.forEach(element => {
|
||||
if (element && element.Key && element.Key.startsWith(prefix)) {
|
||||
element.Value.splice(0);
|
||||
if (element && element.key && element.key.startsWith(prefix)) {
|
||||
element.value.splice(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -85,6 +85,6 @@ export class ValidationErrorModel implements Serializable<ValidationErrorModel>
|
|||
}
|
||||
|
||||
class ErrorMessageItem {
|
||||
Key: string;
|
||||
Value: Array<string> = [];
|
||||
key: string;
|
||||
value: Array<string> = [];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue