mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
AAE-24018 Readonly dropdown with the rest config don't fetch options when form rule change it to not readonly (#9959)
* AAE-24018 Update dropdown-cloud.widget * AAE-24018 Upadate dropdown.widget * AAE-24018 Small update
This commit is contained in:
committed by
GitHub
parent
9cb01e2085
commit
72ea94e928
@@ -15,7 +15,9 @@
|
||||
<mat-option id="readonlyOption" *ngIf="isReadOnlyType()" [value]="field.value">{{field.value}}</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<error-widget [error]="field.validationSummary"></error-widget>
|
||||
<error-widget class="adf-dropdown-required-message" *ngIf="showRequiredMessage()"
|
||||
<ng-container *ngIf="!isReadOnlyField">
|
||||
<error-widget [error]="field.validationSummary"></error-widget>
|
||||
<error-widget class="adf-dropdown-required-message" *ngIf="showRequiredMessage()"
|
||||
required="{{ 'FORM.FIELD.REQUIRED' | translate }}"></error-widget>
|
||||
</ng-container>
|
||||
</div>
|
||||
|
@@ -17,7 +17,15 @@
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { WidgetVisibilityService, FormFieldOption, FormFieldModel, FormModel, FormFieldTypes, CoreTestingModule } from '@alfresco/adf-core';
|
||||
import {
|
||||
WidgetVisibilityService,
|
||||
FormFieldOption,
|
||||
FormFieldModel,
|
||||
FormModel,
|
||||
FormFieldTypes,
|
||||
CoreTestingModule,
|
||||
ErrorMessageModel
|
||||
} from '@alfresco/adf-core';
|
||||
import { DropdownWidgetComponent } from './dropdown.widget';
|
||||
import { TaskFormService } from '../../services/task-form.service';
|
||||
import { ProcessDefinitionService } from '../../services/process-definition.service';
|
||||
@@ -66,27 +74,40 @@ describe('DropdownWidgetComponent', () => {
|
||||
expect(taskFormService.getRestFieldValues).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should request field values from service', () => {
|
||||
describe('requesting field options', () => {
|
||||
let getRestFieldValuesSpy: jasmine.Spy;
|
||||
const taskId = '<form-id>';
|
||||
const fieldId = '<field-id>';
|
||||
|
||||
const form = new FormModel({
|
||||
taskId
|
||||
beforeEach(() => {
|
||||
getRestFieldValuesSpy = spyOn(taskFormService, 'getRestFieldValues').and.returnValue(of([]));
|
||||
|
||||
widget.field = new FormFieldModel(new FormModel({ taskId }), { id: fieldId, restUrl: '<url>' });
|
||||
});
|
||||
|
||||
widget.field = new FormFieldModel(form, {
|
||||
id: fieldId,
|
||||
restUrl: '<url>'
|
||||
it('should request options from service when form is NOT readonly', () => {
|
||||
widget.field.form.readOnly = false;
|
||||
widget.ngOnInit();
|
||||
|
||||
expect(getRestFieldValuesSpy).toHaveBeenCalledWith(taskId, fieldId);
|
||||
});
|
||||
|
||||
spyOn(taskFormService, 'getRestFieldValues').and.returnValue(
|
||||
new Observable((observer) => {
|
||||
observer.next(null);
|
||||
observer.complete();
|
||||
})
|
||||
);
|
||||
it('should NOT request options from service when form is readonly', () => {
|
||||
widget.field.form.readOnly = true;
|
||||
widget.ngOnInit();
|
||||
|
||||
expect(getRestFieldValuesSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should NOT display any error when widget is readonly', () => {
|
||||
widget.field = new FormFieldModel(new FormModel({}, undefined, false), { readOnly: true });
|
||||
widget.field.validationSummary = { message: 'Some error occurred' } as ErrorMessageModel;
|
||||
|
||||
widget.ngOnInit();
|
||||
expect(taskFormService.getRestFieldValues).toHaveBeenCalledWith(taskId, fieldId);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(element.querySelector('.adf-dropdown-required-message')).toBeNull();
|
||||
});
|
||||
|
||||
it('should preserve empty option when loading fields', () => {
|
||||
|
@@ -52,7 +52,7 @@ export class DropdownWidgetComponent extends WidgetComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
if (this.field?.restUrl) {
|
||||
if (this.field?.restUrl && !this.isReadOnlyForm()) {
|
||||
if (this.field.form.taskId) {
|
||||
this.getValuesByTaskId();
|
||||
} else {
|
||||
@@ -102,4 +102,12 @@ export class DropdownWidgetComponent extends WidgetComponent implements OnInit {
|
||||
showRequiredMessage(): boolean {
|
||||
return (this.isInvalidFieldRequired() || this.field.value === 'empty') && this.isTouched();
|
||||
}
|
||||
|
||||
get isReadOnlyField(): boolean {
|
||||
return this.field.readOnly;
|
||||
}
|
||||
|
||||
private isReadOnlyForm(): boolean {
|
||||
return !!this.field?.form?.readOnly;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user