[ADF-3427] fixed wrong validation for dropdown widget and date widget (#3745)

* [ADF-3427] fixed wrong validation for dropdown widget and date widget

* [ADF-3427] fixed unit test
This commit is contained in:
Vito 2018-09-10 14:47:35 +01:00 committed by Eugenio Romano
parent 5b534c409f
commit 04799f0c95
4 changed files with 9 additions and 8 deletions

View File

@ -9,8 +9,9 @@
[id]="column.id" [id]="column.id"
[required]="column.required" [required]="column.required"
[disabled]="!column.editable" [disabled]="!column.editable"
(focusout)="onDateChanged($event.srcElement.value)"> (focusout)="onDateChanged($event.srcElement.value)"
(dateChange)="onDateChanged($event)">
<mat-datepicker-toggle *ngIf="column.editable" matSuffix [for]="datePicker" class="adf-date-editor-button" ></mat-datepicker-toggle> <mat-datepicker-toggle *ngIf="column.editable" matSuffix [for]="datePicker" class="adf-date-editor-button" ></mat-datepicker-toggle>
</mat-form-field> </mat-form-field>
<mat-datepicker #datePicker (dateChange)="onDateChanged($event)" [touchUi]="true"></mat-datepicker> <mat-datepicker #datePicker [touchUi]="true"></mat-datepicker>
</div> </div>

View File

@ -67,7 +67,7 @@ describe('DateEditorComponent', () => {
}); });
it('should update row value upon user input', () => { it('should update row value upon user input', () => {
const input = '14-03-2016'; const input = {value: '14-03-2016' };
component.ngOnInit(); component.ngOnInit();
component.onDateChanged(input); component.onDateChanged(input);
@ -78,7 +78,7 @@ describe('DateEditorComponent', () => {
it('should flush value on user input', () => { it('should flush value on user input', () => {
spyOn(table, 'flushValue').and.callThrough(); spyOn(table, 'flushValue').and.callThrough();
const input = '14-03-2016'; const input = {value: '14-03-2016' };
component.ngOnInit(); component.ngOnInit();
component.onDateChanged(input); component.onDateChanged(input);

View File

@ -65,12 +65,12 @@ export class DateEditorComponent implements OnInit {
let momentDateAdapter = <MomentDateAdapter> this.dateAdapter; let momentDateAdapter = <MomentDateAdapter> this.dateAdapter;
momentDateAdapter.overrideDisplyaFormat = this.DATE_FORMAT; momentDateAdapter.overrideDisplyaFormat = this.DATE_FORMAT;
this.value = moment(this.table.getCellValue(this.row, this.column), this.DATE_FORMAT); this.value = moment(this.table.getCellValue(this.row, this.column), 'YYYY-MM-DD');
} }
onDateChanged(newDateValue) { onDateChanged(newDateValue) {
if (newDateValue) { if (newDateValue && newDateValue.value) {
let momentDate = moment(newDateValue, this.DATE_FORMAT, true); let momentDate = moment(newDateValue.value, this.DATE_FORMAT, true);
if (!momentDate.isValid()) { if (!momentDate.isValid()) {
this.row.value[this.column.id] = ''; this.row.value[this.column.id] = '';

View File

@ -8,7 +8,7 @@
[(ngModel)]="value" [(ngModel)]="value"
[required]="column.required" [required]="column.required"
[disabled]="!column.editable" [disabled]="!column.editable"
(change)="onValueChanged(row, column, $event)"> (selectionChange)="onValueChanged(row, column, $event)">
<mat-option></mat-option> <mat-option></mat-option>
<mat-option *ngFor="let opt of options" [value]="opt.name" [id]="opt.id">{{opt.name}}</mat-option> <mat-option *ngFor="let opt of options" [value]="opt.name" [id]="opt.id">{{opt.name}}</mat-option>
</mat-select> </mat-select>