[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Safeguard to avoid any possible duplication of the autocomplete element

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68cc4c465b996_2cdec7418265@gitlab-sidekiq-low-urgency-cpu-bound-v2-7fccb69b87-k8d96.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
a8828fb0 by Merci Jacob at 2025-09-18T17:48:18+00:00
[FIX] Safeguard to avoid any possible duplication of the autocomplete element
---
* [FIX] Safeguard to avoid any possible duplication of the autocomplete element

See merge request tikiwiki/tiki!8604

- - - - -


2 changed files:

- src/js/vue-widgets/element-plus-ui/src/tests/utils/applyAutocomplete.test.js
- src/js/vue-widgets/element-plus-ui/src/utils/applyAutocomplete.js


Changes:

=====================================
src/js/vue-widgets/element-plus-ui/src/tests/utils/applyAutocomplete.test.js
=====================================
@@ -42,6 +42,18 @@ describe("applyAutocomplete", () => {
         expect(expectedAutoCompleteElement.getAttribute("source-list")).toBe(JSON.stringify(givenSourceList));
     });
 
+    test("should not generate a new autocomplete element if one already exists for the given input element", () => {
+        const givenInput = document.createElement("input");
+        document.body.appendChild(givenInput);
+        const givenRemoteSourceUrl = "https://foo.bar";
+
+        const firstAutoCompleteElement = applyAutocomplete(givenInput, givenRemoteSourceUrl);
+
+        const secondAutoCompleteElement = applyAutocomplete(givenInput, givenRemoteSourceUrl);
+
+        expect(firstAutoCompleteElement).toBe(secondAutoCompleteElement);
+    });
+
     test("given a select callback is provided, it should get fired when the autocomplete element emits a select event", () => {
         const givenInput = document.createElement("input");
         document.body.appendChild(givenInput);


=====================================
src/js/vue-widgets/element-plus-ui/src/utils/applyAutocomplete.js
=====================================
@@ -29,6 +29,11 @@ export default function applyAutocomplete(element, remoteSourceUrl = null, sourc
         elementPlusInput.remove();
     }
 
+    const uiRef = element.getAttribute("element-plus-ref");
+    if (uiRef && document.querySelector(`el-autocomplete#${uiRef}`)) {
+        return document.querySelector(`el-autocomplete#${uiRef}`);
+    }
+
     const elementUniqueId = Math.random().toString(36).substring(7);
     const elementPlusUi = document.createElement("el-autocomplete");
     elementPlusUi.setAttribute("id", elementUniqueId);



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/a8828fb05fe7ae4080696860b2ca6c22797f58eb

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/a8828fb05fe7ae4080696860b2ca6c22797f58eb
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.