Skip to content

Commit

Permalink
[Autocomplete] Avoid destroying on disconnect
Browse files Browse the repository at this point in the history
When moving the element, the disconnect/connect process can cause the underlying value to be lost
  • Loading branch information
weaverryan committed Oct 21, 2023
1 parent 97fe2cd commit 4d90f32
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
19 changes: 10 additions & 9 deletions src/Autocomplete/assets/dist/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,21 @@ class default_1 extends Controller {
}
}
connect() {
if (this.urlValue) {
this.tomSelect = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_createAutocompleteWithRemoteData).call(this, this.urlValue, this.hasMinCharactersValue ? this.minCharactersValue : null);
return;
}
if (this.optionsAsHtmlValue) {
this.tomSelect = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_createAutocompleteWithHtmlContents).call(this);
return;
if (!this.tomSelect) {
if (this.urlValue) {
this.tomSelect = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_createAutocompleteWithRemoteData).call(this, this.urlValue, this.hasMinCharactersValue ? this.minCharactersValue : null);
return;
}
if (this.optionsAsHtmlValue) {
this.tomSelect = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_createAutocompleteWithHtmlContents).call(this);
return;
}
this.tomSelect = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_createAutocomplete).call(this);
}
this.tomSelect = __classPrivateFieldGet(this, _default_1_instances, "m", _default_1_createAutocomplete).call(this);
this.startMutationObserver();
}
disconnect() {
this.stopMutationObserver();
this.tomSelect.destroy();
}
getMaxOptions() {
return this.selectElement ? this.selectElement.options.length : 50;
Expand Down
26 changes: 14 additions & 12 deletions src/Autocomplete/assets/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,30 @@ export default class extends Controller {
}

connect() {
if (this.urlValue) {
this.tomSelect = this.#createAutocompleteWithRemoteData(
this.urlValue,
this.hasMinCharactersValue ? this.minCharactersValue : null
);
if (!this.tomSelect) {
if (this.urlValue) {
this.tomSelect = this.#createAutocompleteWithRemoteData(
this.urlValue,
this.hasMinCharactersValue ? this.minCharactersValue : null
);

return;
}

return;
}
if (this.optionsAsHtmlValue) {
this.tomSelect = this.#createAutocompleteWithHtmlContents();

if (this.optionsAsHtmlValue) {
this.tomSelect = this.#createAutocompleteWithHtmlContents();
return;
}

return;
this.tomSelect = this.#createAutocomplete();
}

this.tomSelect = this.#createAutocomplete();
this.startMutationObserver();
}

disconnect() {
this.stopMutationObserver();
this.tomSelect.destroy();
}

#getCommonConfig(): Partial<TomSettings> {
Expand Down

0 comments on commit 4d90f32

Please sign in to comment.