I mount TomSelect like this:
\nnew TomSelect('.combo-box',{\n create: true,\n load: async (query, callback) => {\n let results = up.request('/tags?query=' + encodeURIComponent(query))\n callback(results.json)\n }\n});The /tags endpoint returns JSON with matching tags like this:
[\n { \"text\": \"matching-tag1\", \"value\": \"123\" },\n { \"text\": \"matching-tag2\", \"value\": \"124\" }\n]-
|
https://developers.arcgis.com/calcite-design-system/components/combobox/ is an example of a searchable multi-input. How would folks recommend building something similar in Unpoly? The tricky bits are deleting a tag, and adding a tag. The existing examples for Unpoly mostly have a single value being operated on. My first attempt was a popup layer that allows searching, and clicking an item in the layer would accept it, where it would be added into the parent layer. Curious to know if there are more elegant solutions. My specific use case is adding tags to a blog post - if a tag already exists, it should be easy for users to quickly add it. If it doesn't exist, a user should be able to just type it out and click a button to add it. The number of tags is too high to be sent in memory to the client. |
Beta Was this translation helpful? Give feedback.
-
I only use an overlay if the "tag" is a structured record that is more complicated to find or create. E.g. when I need paginated search results, or when creating the tag involves a form with multiple fields and validations.
For standard multi-selects I'm using one of the many JavaScript based select replacements, and mount them from a compiler. There are some many intricate details in regards to styling, keyboard input, etc. that I don't want to reinvent this unless I need a very custom solution. I'm not familiar with the Calcite Design System you linked, but e.g. with Tom Select I would have HTML like this: <select class="combo-box" multiple></select>I mount TomSelect like this: new TomSelect('.combo-box',{
create: true,
load: async (query, callback) => {
let results = up.request('/tags?query=' + encodeURIComponent(query))
callback(results.json)
}
});The [
{ "text": "matching-tag1", "value": "123" },
{ "text": "matching-tag2", "value": "124" }
] |
Beta Was this translation helpful? Give feedback.
I only use an overlay if the "tag" is a structured record that is more complicated to find or create. E.g. when I need paginated search results, or when creating the tag involves a form with multiple fields and validations.
For standard multi-selects I'm using one of the many JavaScript based select replacements, and mount them from a compiler. There are some many intricate details in regards to styling, keyboard input, etc. that I don't want to reinvent this unless I need a very…