Skip to content

fix: [FluentCombobox uses Text instead of Value] in [FluentCombobox] #3734

@Programmierhans

Description

@Programmierhans

🐛 Bug Report

Having a List with value and text, the FluentCombox uses the text-column as value and text.

💻 Repro or Code Sample

Having a table like:
Value Text
"1" "One"
"2" "Two"

The FluentCombobox displays the Text (One) but internally also uses "One" as value instead of using the value "1".

`@page "/BugComboBox"
@rendermode InteractiveServer
<FluentCombobox Items=@stringOptions
TOption="Option"
OptionText="@(i => i.Text)"
OptionValue="@(i => i.Value)"
@bind-Value="@StringValue" />

Selected Value: @StringValue

@code {
string? stringValue;

List<Option<string>> stringOptions = new()
    {
        { new Option<string> { Value = "1", Text = "One" } },
        { new Option<string> { Value = "2", Text = "Two"} },
        { new Option<string> { Value = "3", Text = "Three" } }

    };

}
`

🤔 Expected Behavior

The FluentCombobox should use the value-member and not the text-member to store in the bound property

..> the Selected Value should show 1/2/3 and not One/Two/Three when the user selects an entry from the ComboBox

😯 Current Behavior

The FluentCombobox uses a wrong sequence to read the value.
It takes the Text and if not available it falls down to the Value and if not available it executes the ToString.

protected override string? GetOptionValue(TOption? item) { if (item != null) { return OptionText.Invoke(item) ?? OptionValue.Invoke(item) ?? item.ToString(); } else { return null; } }

💁 Possible Solution

by removing the GetOptionValue overload in the FluentCombobox, the code from the ListComponentBase would be invoked. And in the ListComponentBase the sequence is what i would expect.
It takes the Value and if not available it falls back to Text and then to the ToString

protected virtual string? GetOptionValue(TOption? item) { if (item != null) { return OptionValue?.Invoke(item) ?? OptionText?.Invoke(item) ?? item?.ToString(); } else { return null; } }

🔦 Context

I detected this because the FluentCombobox always writes the visible value back to the datastore instead of the value behind the text.

🌍 Your Environment

I used the latest Fluent 4.11.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions