Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix inputName for calendar create form

Oliver Günther08352fff8c20
diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html
index ab0184f0105..b49de6521b9 100644
--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html
+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html
@@ -1,9 +1,10 @@
<div class="inline-label">
- <input *ngIf="inputName"
- [ngModel]="mappedInputValue"
- type="hidden"
- [attr.name]="inputName"
- [attr.data-action]="hiddenFieldAction">
+ <input
+ #syncedInput
+ *ngIf="inputName"
+ type="hidden"
+ [attr.name]="inputName"
+ [attr.data-action]="hiddenFieldAction">
<ng-select
#ngSelectInstance
[(ngModel)]="model"
diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
index 1b1feeeb2bd..6dad618001c 100644
--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
@@ -21,39 +21,28 @@ import {
ViewChild,
ViewContainerRef,
} from '@angular/core';
-import {
- DropdownPosition,
- NgSelectComponent,
-} from '@ng-select/ng-select';
-import {
- BehaviorSubject,
- merge,
- NEVER,
- Observable,
- of,
- Subject,
- timer,
-} from 'rxjs';
-import {
- debounce,
- distinctUntilChanged,
- filter,
- switchMap,
- tap,
-} from 'rxjs/operators';
+import { DropdownPosition, NgSelectComponent } from '@ng-select/ng-select';
+import { BehaviorSubject, merge, NEVER, Observable, of, Subject, timer } from 'rxjs';
+import { debounce, distinctUntilChanged, filter, switchMap, tap } from 'rxjs/operators';
import { GroupValueFn } from '@ng-select/ng-select/lib/ng-select.component';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
-import { Highlighting } from 'core-app/features/work-packages/components/wp-fast-table/builders/highlighting/highlighting.functions';
+import {
+ Highlighting,
+} from 'core-app/features/work-packages/components/wp-fast-table/builders/highlighting/highlighting.functions';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { OpAutocompleterFooterTemplateDirective } from 'core-app/shared/components/autocompleter/autocompleter-footer-template/op-autocompleter-footer-template.directive';
+import {
+ OpAutocompleterFooterTemplateDirective,
+} from 'core-app/shared/components/autocompleter/autocompleter-footer-template/op-autocompleter-footer-template.directive';
import { OpAutocompleterService } from './services/op-autocompleter.service';
import { OpAutocompleterHeaderTemplateDirective } from './directives/op-autocompleter-header-template.directive';
import { OpAutocompleterLabelTemplateDirective } from './directives/op-autocompleter-label-template.directive';
import { OpAutocompleterOptionTemplateDirective } from './directives/op-autocompleter-option-template.directive';
-import { repositionDropdownBugfix } from 'core-app/shared/components/autocompleter/op-autocompleter/autocompleter.helper';
+import {
+ repositionDropdownBugfix,
+} from 'core-app/shared/components/autocompleter/op-autocompleter/autocompleter.helper';
import { populateInputsFromDataset } from 'core-app/shared/components/dataset-inputs';
import { ControlValueAccessor } from '@angular/forms';
import { ID } from '@datorama/akita';
@@ -247,6 +236,8 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet
@ViewChild('ngSelectInstance') ngSelectInstance:NgSelectComponent;
+ @ViewChild('syncedInput') syncedInput:ElementRef<HTMLInputElement>;
+
@ContentChild(OpAutocompleterOptionTemplateDirective, { read: TemplateRef })
projectedOptionTemplate:TemplateRef<Element>;
@@ -384,6 +375,7 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet
}
public changed(val:unknown):void {
+ this.syncHiddenField(this.mappedInputValue);
this.change.emit(val);
this.cdRef.detectChanges();
}
@@ -512,7 +504,7 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet
});
}
- private get templateInjector() {
+ protected get templateInjector() {
return Injector.create(
{
providers: [{ provide: OpAutocompleterComponent, useValue: this }],
@@ -520,4 +512,13 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet
},
);
}
+
+ protected syncHiddenField(mappedInputValue:string) {
+ const input = this.syncedInput?.nativeElement;
+ if (input) {
+ input.value = mappedInputValue;
+ const event = new Event('change');
+ input.dispatchEvent(event);
+ }
+ }
}
diff --git a/modules/calendar/app/views/calendar/calendars/_form.html.erb b/modules/calendar/app/views/calendar/calendars/_form.html.erb
index 4350743ca0b..aabe44cbe64 100644
--- a/modules/calendar/app/views/calendar/calendars/_form.html.erb
+++ b/modules/calendar/app/views/calendar/calendars/_form.html.erb
@@ -44,9 +44,9 @@ See COPYRIGHT and LICENSE files for more details.
<div class="form--field-container">
<%= angular_component_tag 'opce-project-autocompleter',
inputs: {
- filters: [{ name: 'user_action', operator: '=', values: ['calendars/create'] }],
- name: 'project_id',
- model: @project,
+ apiFilters: [['user_action', '=', ['calendars/create']]],
+ inputName: 'project_id',
+ inputValue: @project&.id,
appendTo: 'body',
},
id: 'project_id',
diff --git a/modules/meeting/app/views/meetings/_form.html.erb b/modules/meeting/app/views/meetings/_form.html.erb
index 04efda816ce..ff354c53445 100644
--- a/modules/meeting/app/views/meetings/_form.html.erb
+++ b/modules/meeting/app/views/meetings/_form.html.erb
@@ -89,7 +89,7 @@ See COPYRIGHT and LICENSE files for more details.
inputs: {
filters: [{ name: 'user_action', operator: '=', values: ['meetings/create'] }],
inputName: 'project_id',
- model: @project,
+ inputValue: @project&.id,
appendTo: 'body',
hiddenFieldAction: 'change->refresh-on-form-changes#triggerTurboStream',
},