AAE-24992 Form rules for fields (#10245)

* AAE-24992 Add an ability to call a process on a form event

* extract filter events

* tmp

* add unit
This commit is contained in:
Bartosz Sekula
2024-09-30 14:13:32 -04:00
committed by GitHub
parent 0139273914
commit dfbf08e3a8
3 changed files with 38 additions and 6 deletions

View File

@@ -1056,5 +1056,24 @@ describe('DropdownCloudWidgetComponent', () => {
const failedErrorMsgElement = fixture.debugElement.query(By.css('.adf-dropdown-failed-message'));
expect(failedErrorMsgElement).toBeNull();
});
it('should update options when form variable changes', async () => {
const field = getVariableDropdownWidget('json-form-variable', 'countries', 'id', 'name', undefined, mockFormVariableWithJson);
widget.field = field;
fixture.detectChanges();
field.form.variables[0]['value']['countries'] = [{ id: 'NEW', name: 'New Country' }];
formService.onFormVariableChanged.next({ field });
const dropdown = await loader.getHarness(MatSelectHarness.with({ selector: '.adf-select' }));
await dropdown.open();
expect(widget.field.options.length).toEqual(1);
const allOptions = await dropdown.getOptions();
expect(await allOptions[0].getText()).toEqual('New Country');
expect(allOptions.length).toEqual(1);
});
});
});

View File

@@ -124,13 +124,13 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
}
ngOnInit() {
this.setPreviewState();
this.setupDropdown();
this.checkFieldOptionsSource();
this.updateOptions();
this.initFormControl();
this.initFilter();
this.formService.onFormVariableChanged.subscribe(({ field }) => {
if (field.id === this.field.id) {
this.setupDropdown();
}
});
}
ngOnDestroy() {
@@ -164,6 +164,16 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
this.onFieldChanged(field);
}
private setupDropdown(): void {
this.setPreviewState();
this.checkFieldOptionsSource();
this.updateOptions();
this.initFormControl();
this.initFilter();
}
private initFormControl(): void {
if (this.field?.required) {
this.dropdownControl.addValidators([Validators.required]);