mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-1921] fixed error message for dynamic table (#2696)
* [ADF-1921] fixed error message for dynamic table * [ADF-1921] removed console log
This commit is contained in:
@@ -41,7 +41,7 @@ export class DateCellValidator implements CellValidator {
|
||||
if (!dateValue.isValid()) {
|
||||
if (summary) {
|
||||
summary.isValid = false;
|
||||
summary.text = `Invalid '${column.name}' format.`;
|
||||
summary.message = `Invalid '${column.name}' format.`;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@@ -17,9 +17,14 @@
|
||||
|
||||
/* tslint:disable:component-selector */
|
||||
|
||||
export interface DynamicRowValidationSummary {
|
||||
import { ErrorMessageModel } from '../core/index';
|
||||
|
||||
export class DynamicRowValidationSummary extends ErrorMessageModel {
|
||||
|
||||
isValid: boolean;
|
||||
text: string;
|
||||
|
||||
constructor(json?: any) {
|
||||
super(json);
|
||||
this.isValid = json.isValid;
|
||||
}
|
||||
}
|
||||
|
@@ -145,10 +145,10 @@ export class DynamicTableModel extends FormWidgetModel {
|
||||
}
|
||||
|
||||
validateRow(row: DynamicTableRow): DynamicRowValidationSummary {
|
||||
const summary = <DynamicRowValidationSummary> {
|
||||
const summary = new DynamicRowValidationSummary( {
|
||||
isValid: true,
|
||||
text: null
|
||||
};
|
||||
message: null
|
||||
});
|
||||
|
||||
const event = new ValidateDynamicTableRowEvent(this.form, this.field, row, summary);
|
||||
this.formService.validateDynamicTableRow.next(event);
|
||||
|
@@ -33,7 +33,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<error-widget [error]="validationSummary.text"></error-widget>
|
||||
<error-widget [error]="validationSummary"></error-widget>
|
||||
<div>
|
||||
<button mat-button (click)="onCancelChanges()">Cancel</button>
|
||||
<button mat-button (click)="onSaveChanges()">Save</button>
|
||||
|
@@ -37,7 +37,7 @@ describe('RowEditorComponent', () => {
|
||||
|
||||
it('should be valid upon init', () => {
|
||||
expect(component.validationSummary.isValid).toBeTruthy();
|
||||
expect(component.validationSummary.text).toBeNull();
|
||||
expect(component.validationSummary.message).toBe('');
|
||||
});
|
||||
|
||||
it('should emit [cancel] event', (done) => {
|
||||
@@ -58,7 +58,7 @@ describe('RowEditorComponent', () => {
|
||||
|
||||
it('should emit [save] event', (done) => {
|
||||
spyOn(component.table, 'validateRow').and.returnValue(
|
||||
<DynamicRowValidationSummary> {isValid: true, text: null}
|
||||
<DynamicRowValidationSummary> {isValid: true, message: null}
|
||||
);
|
||||
component.save.subscribe(e => {
|
||||
expect(e.table).toBe(component.table);
|
||||
@@ -71,7 +71,7 @@ describe('RowEditorComponent', () => {
|
||||
|
||||
it('should not emit [save] event for invalid row', () => {
|
||||
spyOn(component.table, 'validateRow').and.returnValue(
|
||||
<DynamicRowValidationSummary> {isValid: false, text: 'error'}
|
||||
<DynamicRowValidationSummary> {isValid: false, message: 'error'}
|
||||
);
|
||||
let raised = false;
|
||||
component.save.subscribe(e => raised = true);
|
||||
|
@@ -45,7 +45,11 @@ export class RowEditorComponent {
|
||||
@Output()
|
||||
cancel: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
validationSummary: DynamicRowValidationSummary = <DynamicRowValidationSummary> { isValid: true, text: null };
|
||||
validationSummary: DynamicRowValidationSummary;
|
||||
|
||||
constructor() {
|
||||
this.validationSummary = new DynamicRowValidationSummary({ isValid: true, message: '' });
|
||||
}
|
||||
|
||||
onCancelChanges() {
|
||||
this.cancel.emit({
|
||||
|
@@ -54,7 +54,7 @@ export class NumberCellValidator implements CellValidator {
|
||||
|
||||
if (summary) {
|
||||
summary.isValid = false;
|
||||
summary.text = `Field '${column.name}' must be a number.`;
|
||||
summary.message = `Field '${column.name}' must be a number.`;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ export class RequiredCellValidator implements CellValidator {
|
||||
if (value === null || value === undefined || value === '') {
|
||||
if (summary) {
|
||||
summary.isValid = false;
|
||||
summary.text = `Field '${column.name}' is required.`;
|
||||
summary.message = `Field '${column.name}' is required.`;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<div class="adf-error-text-container">
|
||||
<div *ngIf="error.isActive()" [@transitionMessages]="_subscriptAnimationState">
|
||||
<div *ngIf="error?.isActive()" [@transitionMessages]="_subscriptAnimationState">
|
||||
<div class="adf-error-text">{{error.message | translate:translateParameters}}</div>
|
||||
<mat-icon class="adf-error-icon">warning</mat-icon>
|
||||
</div>
|
||||
|
@@ -60,7 +60,7 @@ export class ErrorWidgetComponent extends WidgetComponent implements OnChanges {
|
||||
this.required = changes.required.currentValue;
|
||||
this._subscriptAnimationState = 'enter';
|
||||
}
|
||||
if (changes['error']) {
|
||||
if (changes['error'] && changes['error'].currentValue) {
|
||||
if (changes.error.currentValue.isActive()) {
|
||||
this.error = changes.error.currentValue;
|
||||
this.translateParameters = this.error.getAttributesAsJsonObj();
|
||||
|
Reference in New Issue
Block a user