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:
@@ -179,7 +179,7 @@ export class ActivitiComponent implements AfterViewInit, OnDestroy, OnInit {
|
|||||||
const row: DynamicTableRow = e.row;
|
const row: DynamicTableRow = e.row;
|
||||||
if (row && row.value && row.value.name === 'admin') {
|
if (row && row.value && row.value.name === 'admin') {
|
||||||
e.summary.isValid = false;
|
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();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -41,7 +41,7 @@ export class DateCellValidator implements CellValidator {
|
|||||||
if (!dateValue.isValid()) {
|
if (!dateValue.isValid()) {
|
||||||
if (summary) {
|
if (summary) {
|
||||||
summary.isValid = false;
|
summary.isValid = false;
|
||||||
summary.text = `Invalid '${column.name}' format.`;
|
summary.message = `Invalid '${column.name}' format.`;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -17,9 +17,14 @@
|
|||||||
|
|
||||||
/* tslint:disable:component-selector */
|
/* tslint:disable:component-selector */
|
||||||
|
|
||||||
export interface DynamicRowValidationSummary {
|
import { ErrorMessageModel } from '../core/index';
|
||||||
|
|
||||||
|
export class DynamicRowValidationSummary extends ErrorMessageModel {
|
||||||
|
|
||||||
isValid: boolean;
|
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 {
|
validateRow(row: DynamicTableRow): DynamicRowValidationSummary {
|
||||||
const summary = <DynamicRowValidationSummary> {
|
const summary = new DynamicRowValidationSummary( {
|
||||||
isValid: true,
|
isValid: true,
|
||||||
text: null
|
message: null
|
||||||
};
|
});
|
||||||
|
|
||||||
const event = new ValidateDynamicTableRowEvent(this.form, this.field, row, summary);
|
const event = new ValidateDynamicTableRowEvent(this.form, this.field, row, summary);
|
||||||
this.formService.validateDynamicTableRow.next(event);
|
this.formService.validateDynamicTableRow.next(event);
|
||||||
|
@@ -33,7 +33,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<error-widget [error]="validationSummary.text"></error-widget>
|
<error-widget [error]="validationSummary"></error-widget>
|
||||||
<div>
|
<div>
|
||||||
<button mat-button (click)="onCancelChanges()">Cancel</button>
|
<button mat-button (click)="onCancelChanges()">Cancel</button>
|
||||||
<button mat-button (click)="onSaveChanges()">Save</button>
|
<button mat-button (click)="onSaveChanges()">Save</button>
|
||||||
|
@@ -37,7 +37,7 @@ describe('RowEditorComponent', () => {
|
|||||||
|
|
||||||
it('should be valid upon init', () => {
|
it('should be valid upon init', () => {
|
||||||
expect(component.validationSummary.isValid).toBeTruthy();
|
expect(component.validationSummary.isValid).toBeTruthy();
|
||||||
expect(component.validationSummary.text).toBeNull();
|
expect(component.validationSummary.message).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit [cancel] event', (done) => {
|
it('should emit [cancel] event', (done) => {
|
||||||
@@ -58,7 +58,7 @@ describe('RowEditorComponent', () => {
|
|||||||
|
|
||||||
it('should emit [save] event', (done) => {
|
it('should emit [save] event', (done) => {
|
||||||
spyOn(component.table, 'validateRow').and.returnValue(
|
spyOn(component.table, 'validateRow').and.returnValue(
|
||||||
<DynamicRowValidationSummary> {isValid: true, text: null}
|
<DynamicRowValidationSummary> {isValid: true, message: null}
|
||||||
);
|
);
|
||||||
component.save.subscribe(e => {
|
component.save.subscribe(e => {
|
||||||
expect(e.table).toBe(component.table);
|
expect(e.table).toBe(component.table);
|
||||||
@@ -71,7 +71,7 @@ describe('RowEditorComponent', () => {
|
|||||||
|
|
||||||
it('should not emit [save] event for invalid row', () => {
|
it('should not emit [save] event for invalid row', () => {
|
||||||
spyOn(component.table, 'validateRow').and.returnValue(
|
spyOn(component.table, 'validateRow').and.returnValue(
|
||||||
<DynamicRowValidationSummary> {isValid: false, text: 'error'}
|
<DynamicRowValidationSummary> {isValid: false, message: 'error'}
|
||||||
);
|
);
|
||||||
let raised = false;
|
let raised = false;
|
||||||
component.save.subscribe(e => raised = true);
|
component.save.subscribe(e => raised = true);
|
||||||
|
@@ -45,7 +45,11 @@ export class RowEditorComponent {
|
|||||||
@Output()
|
@Output()
|
||||||
cancel: EventEmitter<any> = new EventEmitter<any>();
|
cancel: EventEmitter<any> = new EventEmitter<any>();
|
||||||
|
|
||||||
validationSummary: DynamicRowValidationSummary = <DynamicRowValidationSummary> { isValid: true, text: null };
|
validationSummary: DynamicRowValidationSummary;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.validationSummary = new DynamicRowValidationSummary({ isValid: true, message: '' });
|
||||||
|
}
|
||||||
|
|
||||||
onCancelChanges() {
|
onCancelChanges() {
|
||||||
this.cancel.emit({
|
this.cancel.emit({
|
||||||
|
@@ -54,7 +54,7 @@ export class NumberCellValidator implements CellValidator {
|
|||||||
|
|
||||||
if (summary) {
|
if (summary) {
|
||||||
summary.isValid = false;
|
summary.isValid = false;
|
||||||
summary.text = `Field '${column.name}' must be a number.`;
|
summary.message = `Field '${column.name}' must be a number.`;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,7 @@ export class RequiredCellValidator implements CellValidator {
|
|||||||
if (value === null || value === undefined || value === '') {
|
if (value === null || value === undefined || value === '') {
|
||||||
if (summary) {
|
if (summary) {
|
||||||
summary.isValid = false;
|
summary.isValid = false;
|
||||||
summary.text = `Field '${column.name}' is required.`;
|
summary.message = `Field '${column.name}' is required.`;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<div class="adf-error-text-container">
|
<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>
|
<div class="adf-error-text">{{error.message | translate:translateParameters}}</div>
|
||||||
<mat-icon class="adf-error-icon">warning</mat-icon>
|
<mat-icon class="adf-error-icon">warning</mat-icon>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -60,7 +60,7 @@ export class ErrorWidgetComponent extends WidgetComponent implements OnChanges {
|
|||||||
this.required = changes.required.currentValue;
|
this.required = changes.required.currentValue;
|
||||||
this._subscriptAnimationState = 'enter';
|
this._subscriptAnimationState = 'enter';
|
||||||
}
|
}
|
||||||
if (changes['error']) {
|
if (changes['error'] && changes['error'].currentValue) {
|
||||||
if (changes.error.currentValue.isActive()) {
|
if (changes.error.currentValue.isActive()) {
|
||||||
this.error = changes.error.currentValue;
|
this.error = changes.error.currentValue;
|
||||||
this.translateParameters = this.error.getAttributesAsJsonObj();
|
this.translateParameters = this.error.getAttributesAsJsonObj();
|
||||||
|
Reference in New Issue
Block a user