mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACA-3742] Metadata - constraints validation (#5908)
* card min max value validator * card match value validator * card value length validator * map validators to constraint type * add minmax * update exported validators * register validators based on constraint type * translate errors with parameters * tests
This commit is contained in:
@@ -55,7 +55,7 @@
|
||||
class="adf-textitem-editable-error"
|
||||
*ngIf="hasErrors">
|
||||
<ul>
|
||||
<li *ngFor="let errorMessage of errorMessages">{{ errorMessage | translate }}</li>
|
||||
<li *ngFor="let error of errors">{{ error.message | translate: error }}</li>
|
||||
</ul>
|
||||
</mat-error>
|
||||
|
||||
|
@@ -27,6 +27,7 @@ import { MatChipsModule } from '@angular/material/chips';
|
||||
import { ClipboardService } from '../../../clipboard/clipboard.service';
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CardViewItemValidator } from '../../interfaces/card-view-item-validator.interface';
|
||||
|
||||
describe('CardViewTextItemComponent', () => {
|
||||
|
||||
@@ -441,7 +442,7 @@ describe('CardViewTextItemComponent', () => {
|
||||
});
|
||||
|
||||
it('should set the errorMessages properly if the editedValue is invalid', async () => {
|
||||
const expectedErrorMessages = ['Something went wrong'];
|
||||
const expectedErrorMessages = [{ message: 'Something went wrong' } as CardViewItemValidator];
|
||||
component.property.isValid = () => false;
|
||||
component.property.getValidationErrors = () => expectedErrorMessages;
|
||||
|
||||
@@ -450,7 +451,7 @@ describe('CardViewTextItemComponent', () => {
|
||||
await fixture.whenStable();
|
||||
|
||||
updateTextField(component.property.key, 'updated-value');
|
||||
expect(component.errorMessages).toBe(expectedErrorMessages);
|
||||
expect(component.errors).toBe(expectedErrorMessages);
|
||||
});
|
||||
|
||||
it('should update the property value after a successful update attempt', async () => {
|
||||
|
@@ -22,6 +22,7 @@ import { BaseCardView } from '../base-card-view';
|
||||
import { MatChipInputEvent } from '@angular/material/chips';
|
||||
import { ClipboardService } from '../../../clipboard/clipboard.service';
|
||||
import { TranslationService } from '../../../services/translation.service';
|
||||
import { CardViewItemValidator } from '../../interfaces/card-view-item-validator.interface';
|
||||
|
||||
export const DEFAULT_SEPARATOR = ', ';
|
||||
const templateTypes = {
|
||||
@@ -55,7 +56,7 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
|
||||
multiValueSeparator: string = DEFAULT_SEPARATOR;
|
||||
|
||||
editedValue: string | string[];
|
||||
errorMessages: string[];
|
||||
errors: CardViewItemValidator[];
|
||||
templateType: string;
|
||||
|
||||
constructor(cardViewUpdateService: CardViewUpdateService,
|
||||
@@ -92,7 +93,7 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
|
||||
}
|
||||
|
||||
private resetErrorMessages() {
|
||||
this.errorMessages = [];
|
||||
this.errors = [];
|
||||
}
|
||||
|
||||
update(): void {
|
||||
@@ -102,7 +103,7 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
|
||||
this.property.value = updatedValue;
|
||||
this.resetErrorMessages();
|
||||
} else {
|
||||
this.errorMessages = this.property.getValidationErrors(this.editedValue);
|
||||
this.errors = this.property.getValidationErrors(this.editedValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +177,7 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
|
||||
}
|
||||
|
||||
get hasErrors(): boolean {
|
||||
return this.errorMessages && this.errorMessages.length > 0;
|
||||
return (!!this.errors?.length) ?? false;
|
||||
}
|
||||
|
||||
get isChipViewEnabled(): boolean {
|
||||
|
Reference in New Issue
Block a user