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

fixed decorated select fields visibility and user select field multi value submission and clearing

Jonas Jabari644e25b638ef
diff --git a/app/forms/custom_fields/inputs/base/autocomplete/multi_value_input.rb b/app/forms/custom_fields/inputs/base/autocomplete/multi_value_input.rb
index 37a2304fe83..76de92b4f45 100644
--- a/app/forms/custom_fields/inputs/base/autocomplete/multi_value_input.rb
+++ b/app/forms/custom_fields/inputs/base/autocomplete/multi_value_input.rb
@@ -39,7 +39,8 @@ class CustomFields::Inputs::Base::Autocomplete::MultiValueInput < CustomFields::
def autocomplete_options
{
multiple: true,
- decorated: decorated?
+ decorated: decorated?,
+ append_to:
}
end
diff --git a/app/forms/custom_fields/inputs/base/autocomplete/single_value_input.rb b/app/forms/custom_fields/inputs/base/autocomplete/single_value_input.rb
index 7cc17044668..ce6c7fcd740 100644
--- a/app/forms/custom_fields/inputs/base/autocomplete/single_value_input.rb
+++ b/app/forms/custom_fields/inputs/base/autocomplete/single_value_input.rb
@@ -39,7 +39,8 @@ class CustomFields::Inputs::Base::Autocomplete::SingleValueInput < CustomFields:
def autocomplete_options
{
multiple: false,
- decorated: decorated?
+ decorated: decorated?,
+ append_to:
}
end
diff --git a/app/forms/custom_fields/inputs/base/autocomplete/user_query_utils.rb b/app/forms/custom_fields/inputs/base/autocomplete/user_query_utils.rb
index 50f91b973a8..8aa77123129 100644
--- a/app/forms/custom_fields/inputs/base/autocomplete/user_query_utils.rb
+++ b/app/forms/custom_fields/inputs/base/autocomplete/user_query_utils.rb
@@ -38,7 +38,7 @@ module CustomFields::Inputs::Base::Autocomplete::UserQueryUtils
searchKey: search_key,
inputValue: custom_input_value,
focusDirectly: false,
- appendTo: append_to
+ appendTo: append_to # unlike for the decorated autocompleters, this option has to be passed as camelCase key here!
}
end
@@ -50,10 +50,6 @@ module CustomFields::Inputs::Base::Autocomplete::UserQueryUtils
'any_name_attribute'
end
- def append_to
- options.fetch(:wrapper_id, 'body')
- end
-
def filters
[
{ name: 'type', operator: '=', values: ['User', 'Group', 'PlaceholderUser'] },
diff --git a/app/forms/custom_fields/inputs/base/utils.rb b/app/forms/custom_fields/inputs/base/utils.rb
index 84c3ea806bd..5d517a04fe0 100644
--- a/app/forms/custom_fields/inputs/base/utils.rb
+++ b/app/forms/custom_fields/inputs/base/utils.rb
@@ -57,4 +57,9 @@ module CustomFields::Inputs::Base::Utils
def qa_field_name
@custom_field.attribute_name(:kebab_case)
end
+
+ # used within autocompleter inputs
+ def append_to
+ options.fetch(:wrapper_id, 'body')
+ end
end
diff --git a/app/forms/custom_fields/inputs/multi_user_select_list.rb b/app/forms/custom_fields/inputs/multi_user_select_list.rb
index 54ba380130f..6dc05fe908e 100644
--- a/app/forms/custom_fields/inputs/multi_user_select_list.rb
+++ b/app/forms/custom_fields/inputs/multi_user_select_list.rb
@@ -30,6 +30,15 @@ class CustomFields::Inputs::MultiUserSelectList < CustomFields::Inputs::Base::Au
include CustomFields::Inputs::Base::Autocomplete::UserQueryUtils
form do |custom_value_form|
+ # autocompleter does not set key with blank value if nothing is selected or input is cleared
+ # in order to let acts_as_customizable handle the clearing of the value, we need to set the value to blank via a hidden field
+ # which sends blank if autocompleter is cleared
+ custom_value_form.hidden(**input_attributes.merge(
+ scope_name_to_model: false,
+ name: "#{@object.class.name.downcase}[custom_field_values][#{input_attributes[:name]}][]",
+ value:
+ ))
+
custom_value_form.autocompleter(**input_attributes)
end
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 eff58f05c38..02ee7b9d4a5 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
@@ -9,7 +9,7 @@
<input
*ngFor="let value of mappedInputValue"
type="hidden"
- [attr.name]="inputName"
+ [attr.name]="inputName+'[]'"
[attr.data-action]="hiddenFieldAction"
[value]="value">
</ng-container>