Skip to content

Commit

Permalink
Fix autocomplete issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sinaeftekhar committed Feb 13, 2023
1 parent 838b547 commit 3a74fc4
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
1 change: 0 additions & 1 deletion app/packs/entrypoints/decidim_term_customizer_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ import "src/decidim/term_customizer/admin/multifield/component"
import "src/decidim/term_customizer/admin/constraint_fields"
// import "app/packs/src/decidim/term_customizer/admin/multifield"
import "src/decidim/term_customizer/admin/translation_sets_admin"
import "src/decidim/term_customizer/admin/translations_admin_bulk"
import "src/decidim/term_customizer/admin/translations_admin"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "src/decidim/term_customizer/admin/translations_admin_bulk"
22 changes: 16 additions & 6 deletions app/packs/src/decidim/term_customizer/admin/translations_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ $(() => {
let currentSearch = "";
let selectedTerms = [];

searchInput.addEventListener("keyup", () => {
currentSearch = searchInput.value;
});

// Prevent accidental submit on the autocomplete field
form.addEventListener("submit", (ev) => ev.preventDefault());

Expand Down Expand Up @@ -49,6 +45,11 @@ $(() => {
});
};

const ac = initiate();

searchInput.addEventListener("keyup", () => {
currentSearch = searchInput.value;
});
// Method for hiding the currently selected items
const hideSelectedItems = () => {
const resultsList = searchInput.nextSibling;
Expand All @@ -61,8 +62,6 @@ $(() => {
}
};

initiate();

// Currently not possible in Decidim to get notified when the list is
// modified, so hack it with a MutationObserver.
// Create an observer instance linked to the callback function
Expand Down Expand Up @@ -99,5 +98,16 @@ $(() => {
resultsElement.classList.add("hide");
}
});
setTimeout(() => {
ac.autocomplete.open();
}, 0)
});

document.addEventListener("click", (event) => {
if (!searchInput.nextSibling.contains(event.target)) {
setTimeout(() => {
ac.autocomplete.close();
}, 0)
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ $(document).ready(function () {
}

$(".js-bulk-action-form").find(`.js-translation-id-${translationId}`).prop("checked", checked);
window.selectedTranslationCountUpdate();
window.selectedTranslationsCountUpdate();
});

$(".js-cancel-bulk-action").on("click", function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@

<div class="filters row">
<div class="column medium-4">
<%= form_tag search_translation_set_add_translations_path, method: :get do %>
<%= form_tag search_translation_set_add_translations_path, autocomplete: "off", method: :get do %>
<div class="filters__search">
<%= search_field_tag :term, nil, label: false, id: "tc-autocomplete", class: "autocomplete-input input-group-field", placeholder: t(".search"), data: {
autocomplete: {
searchURL: search_translation_set_add_translations_url,
searchPromptText: t("autocomplete.search_prompt", scope: "decidim.admin")
}
} %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,4 @@
</div>
</div>

<%#= javascript_pack_tag "decidim/term_customizer/admin/translations_admin_bulk" %>
<%= javascript_pack_tag "decidim_term_customizer_admin" %>
<%= javascript_pack_tag "decidim_term_customizer_admin_bulk" %>
3 changes: 2 additions & 1 deletion config/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

# Entrypoints for the module
Decidim::Webpacker.register_entrypoints(
decidim_term_customizer_admin: "#{base_path}/app/packs/entrypoints/decidim_term_customizer_admin.js"
decidim_term_customizer_admin: "#{base_path}/app/packs/entrypoints/decidim_term_customizer_admin.js",
decidim_term_customizer_admin_bulk: "#{base_path}/app/packs/entrypoints/decidim_term_customizer_admin_bulk.js"
)

# Stylesheet imports for admin panel
Expand Down

0 comments on commit 3a74fc4

Please sign in to comment.