Giter Club home page Giter Club logo

Comments (5)

SleepyGrump avatar SleepyGrump commented on August 23, 2024

Yes, please! This would make it truly ready for primetime.

I've got multiple use cases dealing with DB data where the option text should be different from the value passed to an API. An example: six different locations with identical names, all in different places, each with a different ID... you'd better believe we go by the ID!

You might also consider a template of some sort for options. In my example case, options would be formatted something like this:

<Option>
[Location name] ([customer friendly ID])
[address line 1]
[city state zip]
<Button text="Remove">
</Option>

Something that customizable would come in very handy.

from svelte-multiselect.

janosh avatar janosh commented on August 23, 2024

@MelpomeneMU Thanks for the input! Considering this seems to be quite a popular feature, I'll try to start working on it this weekend.

Just to clarify your example, if there are six identically named places in different locations, you must already include some additional information (like country) for your users, right? Else how would they know which of the 6 to pick?

In any case, I do see the value of sending a different value than what is displayed to the user to an API.

Regarding the template string, I believe it would be easiest for devs to do that on their own. Most people just want to render simple strings, so seems overkill to ship the logic required to hydrate a template to everyone regardless of whether they need it or not. It should as simple as running a map() over your array of options with some string interpolation to build the template you need yourself.

On a related note, we might consider parsing labels as HTML though with Svelte's {@html ...} directive in case people want to have tags with inline styles or some such.

from svelte-multiselect.

janosh avatar janosh commented on August 23, 2024

Ok, I think I have something I would tentatively call a beta version of options as objects. Still a few TS issues to sort out. Will try to do some testing tomorrow.

from svelte-multiselect.

janosh avatar janosh commented on August 23, 2024

Turned out to be a bigger refactor than expected. I pushed everything to the object-options branch. No known issues so would be great if everyone interested in this feature could give it a try and report bugs/suggestions before I release this as v2.0.0.

yarn add -D https://github.com/janosh/svelte-multiselect#object-options

from svelte-multiselect.

janosh avatar janosh commented on August 23, 2024

This is released in v2.0.0. 🎉

Note the breaking changes mentioned in #16, mainly that bind:selected now returns objects instead of strings. To get the strings as before, use bind:selectedLabels.

from svelte-multiselect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.