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 multiple values being joined in a single input

Oliver Günther22def47c4c9b
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 b49de6521b9..eff58f05c38 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,10 +1,18 @@
<div class="inline-label">
<input
#syncedInput
- *ngIf="inputName"
+ *ngIf="inputName && !(multiple && multipleAsSeparateInputs)"
type="hidden"
[attr.name]="inputName"
[attr.data-action]="hiddenFieldAction">
+ <ng-container *ngIf="multiple && multipleAsSeparateInputs">
+ <input
+ *ngFor="let value of mappedInputValue"
+ type="hidden"
+ [attr.name]="inputName"
+ [attr.data-action]="hiddenFieldAction"
+ [value]="value">
+ </ng-container>
<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 d7cbb1e966b..a4946630785 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
@@ -104,7 +104,9 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet
@Input() public inputName?:string;
- @Input() public inputValue?:string;
+ @Input() public inputValue?:string|string[];
+
+ @Input() public multipleAsSeparateInputs:boolean = true;
@Input() public inputBindValue = 'id';
@@ -141,7 +143,7 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet
@Input() public classes?:string;
- @Input() public multiple?:boolean = false;
+ @Input() public multiple:boolean = false;
@Input() public openDirectly?:boolean = false;
@@ -301,7 +303,7 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet
if (this.inputValue && !this.model) {
this
.opAutocompleterService
- .loadValue(this.inputValue, this.resource)
+ .loadValue(this.inputValue, this.resource, this.multiple)
.subscribe((resource) => {
this.model = resource as unknown as T;
this.syncHiddenField(this.mappedInputValue);
@@ -343,13 +345,13 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet
});
}
- public get mappedInputValue():string {
+ public get mappedInputValue():string|string[] {
if (!this.model) {
return '';
}
if (Array.isArray(this.model)) {
- return this.model.map((el) => el[this.inputBindValue as 'id']).join(',');
+ return this.model.map((el) => el[this.inputBindValue as 'id'] as string);
}
return this.model[this.inputBindValue as 'id'] as string;
@@ -530,10 +532,10 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet
);
}
- protected syncHiddenField(mappedInputValue:string) {
+ protected syncHiddenField(mappedInputValue:string|string[]) {
const input = this.syncedInput?.nativeElement;
if (input) {
- input.value = mappedInputValue;
+ input.value = Array.isArray(mappedInputValue) ? mappedInputValue.join(',') : mappedInputValue;
const event = new Event('change');
input.dispatchEvent(event);
}
diff --git a/modules/overviews/app/controllers/overviews/overviews_controller.rb b/modules/overviews/app/controllers/overviews/overviews_controller.rb
index fb60ac5f3c1..5e61a596d05 100644
--- a/modules/overviews/app/controllers/overviews/overviews_controller.rb
+++ b/modules/overviews/app/controllers/overviews/overviews_controller.rb
@@ -30,15 +30,13 @@ module ::Overviews
def update_project_custom_values
section = find_project_custom_field_section
- processed_permitted_params = pre_process(permitted_params.project)
-
service_call = ::Projects::UpdateService
.new(
user: current_user,
model: @project
)
.call(
- processed_permitted_params.merge(
+ permitted_params.project.merge(
limit_custom_fields_validation_to_section_id: section.id
)
)
@@ -61,27 +59,6 @@ module ::Overviews
private
- def pre_process(project_params)
- # TODO: find better solution for this:
- # quick fixing wrong submit format of multi user custom fields, should be fixed on the frontend side
- # multi user autocompleter submits a comma separated list of user ids
- # like `project[custom_field_values][40]: 5,4`
- # instead of `project[custom_field_values][40][]: 5` and `project[custom_field_values][40][]: 4`
- # this leads to parsing errors within the project.custom_field_values= method
- # thus we preprocess the params to split the comma separated list into an array here
- eager_loaded_custom_fields = @project.project_custom_fields.to_a
-
- project_params[:custom_field_values].each do |custom_field_id, custom_field_value|
- custom_field = eager_loaded_custom_fields.find { |pcf| pcf.id == custom_field_id.to_i }
-
- if custom_field&.field_format == "user" && custom_field.multi_value?
- project_params[:custom_field_values][custom_field_id] = custom_field_value&.split(",")
- end
- end
-
- project_params
- end
-
def find_project_custom_field_section
ProjectCustomFieldSection.find(params[:section_id])
end