[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:
Vito
2017-11-22 17:22:52 +00:00
committed by Eugenio Romano
parent 220e14cfcd
commit 01ff35a786
11 changed files with 25 additions and 16 deletions

View File

@@ -179,7 +179,7 @@ export class ActivitiComponent implements AfterViewInit, OnDestroy, OnInit {
const row: DynamicTableRow = e.row;
if (row && row.value && row.value.name === 'admin') {
e.summary.isValid = false;
e.summary.text = 'Sorry, wrong value. You cannot use "admin".';
e.summary.message = 'Sorry, wrong value. You cannot use "admin".';
e.preventDefault();
}
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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);

View File

@@ -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>

View File

@@ -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);

View File

@@ -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({

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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>

View File

@@ -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();