[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [FIX] Safeguard to avoid any possible duplication of the autocomplete element
"Merci Jacob \(@mercihabam\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <68cd170ef183d_2c1c988fc340fd@gitlab-sidekiq-low-urgency-cpu-bound-v2-5c44cb6566-dv252.mail> |
Merci Jacob pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki Commits: 10bef053 by Merci Jacob at 2025-09-19T08:40:45+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 (cherry picked from commit a8828fb05fe7ae4080696860b2ca6c22797f58eb) dfdc07f2 [FIX] Safeguard to avoid any possible duplication of the autocomplete element Co-authored-by: Merci Jacob <[email protected]> - - - - - 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/10bef0534a65f47db8d3a0de02877bd669aa0b33 -- View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/10bef0534a65f47db8d3a0de02877bd669aa0b33 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