Skip to content
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

Separate label/value #16866

Merged
merged 2 commits into from
Mar 12, 2016
Merged

Conversation

vlazar
Copy link
Collaborator

@vlazar vlazar commented Mar 12, 2016

This is a cleaned up version of #16852 (sequence #16821 -> #16851 -> #16852 -> this PR)

It is now possible to show a suggestion label in completer, but insert a suggestion value into the input instead.

In addition to String as before, each list item now can also be:

  • a { label, value } Object
  • a [ label, value ] Array

To show full country name in completer, but insert country code into the input you can use these items:

  • { label: "United States", value: "US" }
  • [ "United States", "US" ]

Despite this data format change, old code will continue to work as before. This is taken care by Suggestion(). It uses label property automatically when string is expected anywhere in the API.

One known issue is that accessing suggestion's characters by index won't work with old API. It's easy to fix though. Instead of item[idx] use item.value[idx] or item.label[idx] directly.

In addition to default support for String/Object/Array items, we also add data method, which can be used to support any additional custom item formats and to generate data dynamically, as in changed Email example. The only thing you need to do in this case is to return item in any of String/Array/Object formats supported by default.

Initialization via <datalist> or <ul> with separate label/value is supported as well.

vlazar added 2 commits March 12, 2016 14:03
It is now possible to show a suggestion label in completer,
but insert a suggestion value into the input instead.

In addition to String as before, each list item now can also be:
- a `{ label, value }` Object
- a `[ label, value ]` Array

To show full country name in completer, but insert country code
into the input you can use these items:
- `{ label: "United States", value: "US" }`
- `[ "United States", "US" ]`

Despite this data format change, old code will continue to work
as before. This is taken care by `Suggestion()`. It uses `label`
property automatically when string is expected anywhere in the API.

One known issue is that accessing suggestion's characters by index
won't work with old API. It's easy to fix though. Instead of `item[idx]`
use `item.value[idx]` or `item.label[idx]` directly.

In addition to default support for String/Object/Array items, we
also add `data` method, which can be used to support any additional
custom item formats and to generate data dynamically, as in changed
Email example. The only thing you need to do in this case is to return
item in any of String/Array/Object formats supported by default.
@LeaVerou
Copy link
Owner

Thanks for your continued efforts @vlazar! Nice work!

This was referenced Mar 13, 2016
@vlazar vlazar added this to the v1.1 milestone Mar 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants