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

How to use a non-label field as the input value after selecting #213

Open
ricochenft opened this issue Aug 18, 2023 · 0 comments
Open

How to use a non-label field as the input value after selecting #213

ricochenft opened this issue Aug 18, 2023 · 0 comments

Comments

@ricochenft
Copy link

With the following code from README.md, when selecting from the dropdown, the text from name would populate the input value. What if I want the input field to show code instead?

const colorList = [
  { id: 1, name: "White", code: "#FFFFFF" },
  { id: 2, name: "Red", code: "#FF0000" },
  { id: 3, name: "Yellow", code: "#FF00FF" },
  { id: 4, name: "Green", code: "#00FF00" },
  { id: 5, name: "Blue", code: "#0000FF" },
  { id: 6, name: "Black", code: "#000000" },
]

let selectedColorObject
<AutoComplete items={colorList} bind:selectedItem={selectedColorObject} labelFieldName="name" />

I can somewhat get it working by this hack-ish way:

<AutoComplete
    items={colorList}
    bind:selectedItem={selectedColorObject}
    labelFieldName="code"
>
    <div slot="item" let:item>
        <span>{item.name}</span>
    </div>
</AutoComplete>

But that workaround creates two new problems:

  • searching stops working
  • code highlights while typing no longer work either
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

No branches or pull requests

1 participant