mirror of
https://github.com/opf/openproject.git
synced 2026-06-13 19:20:00 +00:00
Fix/36382 dynamic form not triggering expression properties (#9249)
* Fix * Tests * Fix dangerfile grep * Remove fdescribe Co-authored-by: Oliver Günther <mail@oliverguenther.de>
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
# Fail if jasmine specs contain fdescribe or fit
|
||||
fail("jasmine fdescribe/fit left in tests") if `grep --include '*.spec.ts' -rP 'fdescribe\(|fit\(' frontend/src/`.length > 1
|
||||
fail("jasmine fdescribe/fit left in tests") if `grep --include '*.spec.ts' -rP 'fdescribe\\(|fit\\(' frontend/src/`.length > 1
|
||||
|
||||
# Search for modified components not being made OnPush
|
||||
git.modified_files
|
||||
|
||||
+37
@@ -456,5 +456,42 @@ describe('DynamicFormComponent', () => {
|
||||
|
||||
dynamicFormService.submit$.and.returnValue(defer(() => Promise.resolve('ok')));
|
||||
}));
|
||||
|
||||
// Moving the DynamicForm.form assignment out of the _setupDynamicForm breaks the
|
||||
// expressionProperties execution
|
||||
it('should run expressionProperties', fakeAsync(() => {
|
||||
const [firstField, ...restOfFields] = dynamicFormSettings.fields;
|
||||
const expressionPropertiesSpy = jasmine.createSpy('expressionPropertiesSpy');
|
||||
const firstFieldCopy = {
|
||||
...firstField,
|
||||
expressionProperties: {
|
||||
'templateOptions.test': expressionPropertiesSpy,
|
||||
}
|
||||
};
|
||||
const dynamicFormSettingsForSubmit = {
|
||||
...dynamicFormSettings,
|
||||
fields: [
|
||||
firstFieldCopy,
|
||||
...restOfFields,
|
||||
]
|
||||
}
|
||||
// @ts-ignore
|
||||
dynamicFormService.getSettingsFromBackend$.and.returnValue(defer(() => Promise.resolve(dynamicFormSettingsForSubmit)));
|
||||
dynamicFormService.submit$.and.returnValue(defer(() => Promise.resolve('ok')));
|
||||
|
||||
// Should not show notifications when showNotifications === false
|
||||
component.showNotifications = false;
|
||||
|
||||
component.resourcePath = '/api/v3/projects/1234/form';
|
||||
component.ngOnChanges({});
|
||||
flush();
|
||||
fixture.detectChanges();
|
||||
const submitButton = fixture.debugElement.query(By.css('button[type=submit]'));
|
||||
submitButton.nativeElement.click();
|
||||
|
||||
flush();
|
||||
|
||||
expect(expressionPropertiesSpy).toHaveBeenCalled();
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
+4
-2
@@ -93,7 +93,7 @@ export class DynamicFormComponent extends UntilDestroyedMixin implements OnChang
|
||||
@Input() showValidationErrorsOn:'change'|'blur'|'submit'|'never' = 'submit';
|
||||
@Input() handleSubmit = true;
|
||||
@Input() helpTextAttributeScope:string|undefined;
|
||||
@Input('dynamicFormGroup') form:FormGroup = new FormGroup({});
|
||||
@Input() dynamicFormGroup:FormGroup;
|
||||
|
||||
@Input() set model(payload:IOPFormModel) {
|
||||
if (!this.innerModel && !payload) {
|
||||
@@ -125,6 +125,7 @@ export class DynamicFormComponent extends UntilDestroyedMixin implements OnChang
|
||||
noPathToSubmitToError = `DynamicForm needs a resourcePath input in order to be submitted
|
||||
and validated. Please provide one.`;
|
||||
innerModel:IOPFormModel;
|
||||
form:FormGroup;
|
||||
|
||||
get model() {
|
||||
return this.form.value;
|
||||
@@ -271,7 +272,7 @@ export class DynamicFormComponent extends UntilDestroyedMixin implements OnChang
|
||||
this._setupDynamicForm(dynamicFormSettings);
|
||||
}
|
||||
|
||||
private _setupDynamicForm({ fields, model }:IOPDynamicFormSettings) {
|
||||
private _setupDynamicForm({ fields, model, form }:IOPDynamicFormSettings) {
|
||||
const scopedFields = fields.map(field => ({
|
||||
...field,
|
||||
templateOptions: {
|
||||
@@ -281,6 +282,7 @@ export class DynamicFormComponent extends UntilDestroyedMixin implements OnChang
|
||||
}));
|
||||
this.fields = this.fieldsSettingsPipe ? this.fieldsSettingsPipe(scopedFields) : scopedFields;
|
||||
this.innerModel = model;
|
||||
this.form = this.dynamicFormGroup || form;
|
||||
|
||||
this._changeDetectorRef.detectChanges();
|
||||
}
|
||||
|
||||
+1
@@ -48,6 +48,7 @@ export class DynamicFormService {
|
||||
const formSchema = formConfig._embedded?.schema;
|
||||
const formPayload = formConfig._embedded?.payload;
|
||||
const dynamicForm = {
|
||||
form: new FormGroup({}),
|
||||
fields: this._dynamicFieldsService.getConfig(formSchema, formPayload),
|
||||
model: this._dynamicFieldsService.getModel(formPayload),
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@ import { FormGroup } from "@angular/forms";
|
||||
export interface IOPDynamicFormSettings {
|
||||
fields:IOPFormlyFieldSettings[];
|
||||
model:IOPFormModel;
|
||||
form:FormGroup;
|
||||
}
|
||||
|
||||
export interface IOPFormlyFieldSettings extends FormlyFieldConfig {
|
||||
|
||||
Reference in New Issue
Block a user