mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
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:
@@ -30,6 +30,7 @@ import { ValidateFormFieldEvent } from '../events/validate-form-field.event';
|
||||
import { FormValidationService } from './form-validation-service.interface';
|
||||
import { FormRulesEvent } from '../events/form-rules.event';
|
||||
import { FormSpinnerEvent } from '../events';
|
||||
import { FormFieldModel } from '../components/widgets';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -46,6 +47,8 @@ export class FormService implements FormValidationService {
|
||||
formContentClicked = new Subject<ContentLinkModel>();
|
||||
toggleFormSpinner = new Subject<FormSpinnerEvent>();
|
||||
|
||||
onFormVariableChanged = new Subject<{ field: FormFieldModel; data?: any }>();
|
||||
|
||||
validateForm = new Subject<ValidateFormEvent>();
|
||||
validateFormField = new Subject<ValidateFormFieldEvent>();
|
||||
validateDynamicTableRow = new Subject<FormFieldEvent>();
|
||||
|
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -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]);
|
||||
|
Reference in New Issue
Block a user