question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@bind-Value on FluentCombobox binds to the displayed text, not the value

See original GitHub issue

🐛 Bug Report

FluentCombobox should bind to the value of the selected FluentOption, instead of the displayed part.

💻 Repro or Code Sample

I have a Blazor wasm project. When I make a FluentCombobox, and bind a string using @bind-Value, the contents of the string is set to the diplayed part of the combobox.

@page "/ViewCustomers"
<h1>View Customers</h1>
           Selected Value: @selectedCustValue
            <FluentCombobox Autocomplete="Autocomplete.List" @bind-Value="selectedCustValue">
                @foreach (var cust in customers)
                {
                    <FluentOption Value="@cust.Id.ToString()">@cust.Name</FluentOption>
                }
            </FluentCombobox>
 }

@code {

    string selectedCustValue = "";
    List<Customer>? customers = new(
        new []{new Customer{Id = 0, Name = "abc"}});
}

🤔 Expected Behavior

selectedCustValue should contain the value set in the selected FluentOption (“0” in the example)

😯 Current Behavior

The displayed part of the selected FluentOption is set in SelectedCustValue (“abc” in the example)

🔦 Context

I need the id, since I cannot guarantee that the Name value is unique.

🌍 Your Environment

  • OS & Device: Windows 11
  • Browser Google Chrome
  • .NET and FAST Version .NET 6.0 Microsoft.Fast.Components.FluentUI v. 1.1.0 (LAtest NuGet package)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
vnbaaijcommented, Oct 23, 2022

I’m redoing the FluentCombobox, FluentListbox and FluentSelect for V2. A (strongly typed) SelectedItem will be supported there. I also have the Value working as of now, but that does not reflect a typed in value and I don’t think I can get to that typed in value. I guess it depends on what behavior we expect a combobox to have: 1) an alternative to a select where you can search through the list by typing in the input or 2) a combination (hence the name) of an input and a select list where a use can enter free-form text.

1reaction
radium-vcommented, Feb 9, 2022

@atmgrifter00 With regards to the specification for combobox, this is expected behavior as described in my previous comment. Having separate values for combobox options can conflict with the ability to enter and submit custom values.

A combobox is like a text input with supplementary predetermined options, whereas a select is like a collapsible listbox. In fact, the element internals for combobox use an input, since unlike select, there is no native control which reflects the accessibility requirements of a user-editable combobox.

The reason a combobox doesn’t use the value of its options comes down to avoiding the potential for user-defined values that are similar, but different, from any pre-configured values (ex. “fooBAR” vs “FOObar”). While the autocomplete functionality can do a basic job of filtering the list and auto-filling potential matches, there’s no way to confirm if a user’s input is an incomplete fuzzy search or a specific custom value.

With that said, there are a few useful ways to get the selected items from the DOM:

  • Combobox, Select, and Listbox elements all provide the selectedIndex and selectedOptions properties which can be used to determine which item is currently selected.
  • Option elements have a selected boolean property which can be used instead of checking the class.

My own personal experience with Blazor is limited, so I don’t know if getting the element properties would require hooking it up in this project.

One more alternative would be to use the FluentSelect component, which doesn’t allow for direct user-specified values but does use the values of its selected options for its own. It also supports type-ahead to select the first matching option as you start typing while it’s focused.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to two-way-bind a value in FluentListBox - blazor
Trying this out in a new Blazor project shows that _value does not change when selecting a new value. When I manually set...
Read more >
fix: FluentSelect does not update when SelectedOption ...
When I hit Previous, Previous it does not update. ... fix: Value set from outside of component is not displayed in FluentCombobox. #308....
Read more >
Blazor bind-value vs bind-Value : r/dotnet
i've always use @bind-Value. however, i got a error message "The attribute names could not be inferred from bind attribute 'bind-Value'.
Read more >
PDOStatement::bindValue - Manual
Description ¶ Binds a value to a corresponding named or question mark placeholder in the SQL statement that was used to prepare the...
Read more >
Data Binding - Blazor ComboBox - Documentation
A Value that is non- default will not show the Placeholder . Handling such "unexpected" values is up to the application - for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found