fixed dynamic disabled component after angular 10 upgrade

This commit is contained in:
Giuseppe Digilio
2020-12-02 12:38:26 +01:00
parent 9336693cc7
commit b49d46176b
3 changed files with 39 additions and 23 deletions

View File

@@ -1,13 +1,15 @@
<div> <div>
<div class="form-row align-items-center"> <div class="form-row align-items-center">
<div class="col"> <div class="col">
<input class="form-control" <input class="form-control"
[class.is-invalid]="showErrorMessages" [class.is-invalid]="showErrorMessages"
[value]="modelValuesString" [id]="id"
[disabled]="model.disabled" [name]="model.name"
[type]="model.inputType" [value]="modelValuesString"
[placeholder]="model.placeholder | translate" [disabled]="model.disabled"
[readonly]="model.readOnly"> [type]="model.inputType"
[placeholder]="model.placeholder | translate"
[readonly]="model.readOnly">
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,11 +1,17 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core'; import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
import { DsDynamicDisabledComponent } from './dynamic-disabled.component'; import { FormControl, FormGroup, FormsModule } from '@angular/forms';
import { FormsModule } from '@angular/forms';
import { DynamicFormLayoutService, DynamicFormValidationService } from '@ng-dynamic-forms/core';
import { DynamicDisabledModel } from './dynamic-disabled.model';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { DynamicFormLayoutService, DynamicFormValidationService } from '@ng-dynamic-forms/core';
import { DsDynamicDisabledComponent } from './dynamic-disabled.component';
import { DynamicDisabledModel } from './dynamic-disabled.model';
import {
mockDynamicFormLayoutService,
mockDynamicFormValidationService
} from '../../../../../testing/dynamic-form-mock-services';
describe('DsDynamicDisabledComponent', () => { describe('DsDynamicDisabledComponent', () => {
let comp: DsDynamicDisabledComponent; let comp: DsDynamicDisabledComponent;
@@ -13,25 +19,31 @@ describe('DsDynamicDisabledComponent', () => {
let de: DebugElement; let de: DebugElement;
let el: HTMLElement; let el: HTMLElement;
let model; let model;
let group;
function init() { function init() {
model = new DynamicDisabledModel({ value: 'test', repeatable: false, metadataFields: [], submissionId: '1234', id: '1', hasSelectableMetadata: false }); model = new DynamicDisabledModel({
value: 'test',
repeatable: false,
metadataFields: [],
submissionId: '1234',
id: 'disabledInput',
name: 'disabledInput',
hasSelectableMetadata: false
});
group = new FormGroup({
disabledInput: new FormControl(),
});
} }
beforeEach(async(() => { beforeEach(waitForAsync(() => {
init(); init();
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [DsDynamicDisabledComponent], declarations: [DsDynamicDisabledComponent],
imports: [FormsModule, TranslateModule.forRoot()], imports: [FormsModule, TranslateModule.forRoot()],
providers: [ providers: [
{ { provide: DynamicFormLayoutService, useValue: mockDynamicFormLayoutService },
provide: DynamicFormLayoutService, { provide: DynamicFormValidationService, useValue: mockDynamicFormValidationService },
useValue: {}
},
{
provide: DynamicFormValidationService,
useValue: {}
}
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).compileComponents(); }).compileComponents();
@@ -43,6 +55,7 @@ describe('DsDynamicDisabledComponent', () => {
de = fixture.debugElement; de = fixture.debugElement;
el = de.nativeElement; el = de.nativeElement;
comp.model = model; comp.model = model;
comp.group = group;
fixture.detectChanges(); fixture.detectChanges();
}); });

View File

@@ -1,7 +1,8 @@
import { Component, EventEmitter, Input, Output } from '@angular/core'; import { Component, EventEmitter, Input, Output } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { DynamicFormControlComponent, DynamicFormLayoutService, DynamicFormValidationService } from '@ng-dynamic-forms/core'; import { DynamicFormControlComponent, DynamicFormLayoutService, DynamicFormValidationService } from '@ng-dynamic-forms/core';
import { FormGroup } from '@angular/forms';
import { DynamicDisabledModel } from './dynamic-disabled.model'; import { DynamicDisabledModel } from './dynamic-disabled.model';
/** /**