-
-
Notifications
You must be signed in to change notification settings - Fork 356
[Autocomplete] Tom Select Options Plugins #2657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,12 @@ export default class extends Controller { | |
plugins.virtual_scroll = {}; | ||
} | ||
|
||
if ('plugins' in this.tomSelectOptionsValue && Array.isArray(this.tomSelectOptionsValue.plugins)) { | ||
this.tomSelectOptionsValue.plugins.forEach((pluginName) => { | ||
plugins[pluginName] = {}; | ||
}); | ||
} | ||
|
||
const render: Partial<TomTemplates> = { | ||
no_results: () => { | ||
return `<div class="no-results">${this.noResultsFoundTextValue}</div>`; | ||
|
@@ -214,7 +220,7 @@ export default class extends Controller { | |
config.shouldLoad = () => false; | ||
} | ||
|
||
return this.#mergeObjects(config, this.tomSelectOptionsValue); | ||
return this.#mergeObjects(this.tomSelectOptionsValue, config); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really sure about that, it looks like a BC no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By doing this, we prevent user-provided options from overwriting the configuration created within this function, especially for plugins. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As @Kocal said, it is BC break. By looking at the code, the original idea is: if a user provides some config values, these values always win over default config There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I can revert this change and merge the config with a copy of tomSelectOptionsValue, without the plugins previously merged by a specific process, in order to avoid them being replaced ? |
||
} | ||
|
||
#createAutocomplete(): TomSelect { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given examples (https://tom-select.js.org/plugins/caret-position/ and https://tom-select.js.org/plugins/checkbox-options/) it looks like
plugins
can also be a key-value object.Can't we use a more simple solution like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is treaky : https://tom-select.js.org/docs/plugins/ says we can put just plugin names (simple array) or plugin with options (object in js side). Also with simple assignment we override plugins configuration added line 138 to 150