Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

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.

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

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 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 /tags endpoint returns JSON with matching tags like this:

[
  { "text": "matching-tag1", "value": "123" },
  { "text": "matching-tag2", "value": "124" }
]
You must be logged in to vote
1 reply
@ajusa
Comment options

Thanks for the well written answer! I forgot about things like arrow key functionality, that would be tricky to replicate in a new layer. Ended up using tom-select and it's great!

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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.