Skip to content

Commit

Permalink
Hide the select2 drop-down for units [#4396]
Browse files Browse the repository at this point in the history
  • Loading branch information
awwaiid committed Jun 19, 2024
1 parent 4300a0d commit db4862a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions app/javascript/controllers/select2_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ import "select2"
export default class extends Controller {
static values = {
config: { type: Object, default: {} },
}
hideDropdown: { type: Boolean, default: false }
};

connect() {
$(this.element).select2(this.configValue);
const select2 = $(this.element).select2(this.configValue);

if (this.hideDropdownValue) {
select2.on('select2:open', function (e) {
$('.select2-container--open .select2-dropdown--below').css('display','none');
});
}

/**
* This is a workaround to auto focus on the select2 input when it is opened.
Expand Down
2 changes: 1 addition & 1 deletion app/views/organizations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<% if Flipper.enabled?(:enable_packs) %>
<%= f.label :request_units, 'Custom request units used (please use singular form -- e.g. pack, not packs)' %>
<%= f.select(:request_unit_ids, options_from_collection_for_select(current_organization.request_units, 'id', 'name', current_organization.request_unit_ids), {}, { multiple: true, class: 'form-control custom-select', 'data-controller': 'select2', 'data-select2-config-value': '{"selectOnClose": "true", "tags": "true", "tokenSeparators": [",", "\t"]}'}) %>
<%= f.select(:request_unit_ids, options_from_collection_for_select(current_organization.request_units, 'id', 'name', current_organization.request_unit_ids), {}, { multiple: true, class: 'form-control custom-select', 'data-controller': 'select2', 'data-select2-hide-dropdown-value': true, 'data-select2-config-value': '{"selectOnClose": "true", "tags": "true", "tokenSeparators": [",", "\t"]}'}) %>
<% end %>
<%= f.input :enable_child_based_requests, label: 'Enable partners to make child-based requests?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
Expand Down

0 comments on commit db4862a

Please sign in to comment.