Skip to content
\n

I mount TomSelect like this:

\n
new 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});
\n

The /tags endpoint returns JSON with matching tags like this:

\n
[\n  { \"text\": \"matching-tag1\", \"value\": \"123\" },\n  { \"text\": \"matching-tag2\", \"value\": \"124\" }\n]
","upvoteCount":1,"url":"https://github.com/unpoly/unpoly/discussions/783#discussioncomment-14907048"}}}
Discussion options

You must be logged in to vote

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.

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.

Curious to know if there are more elegant solutions.

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…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ajusa
Comment options

Answer selected by ajusa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants