Blazored / Typeahead

Typeahead control for Blazor applications
https://blazored.github.io/Typeahead/
MIT License
439 stars 103 forks source link

[Bug] Setting selected item to null loses placeholder text #224

Open natiox opened 3 years ago

natiox commented 3 years ago

Description Setting the bound value to null doesn't restore the placeholder text.

To Reproduce

  1. In sample project, Index.razor, Blazored Typeahead - Form example, change SelectedTemplate to handle null so this doesn't crash:
    <SelectedTemplate Context="person">
    @person?.Firstname
    </SelectedTemplate>
  2. Change HandleFormSubmit as follows:
    private void HandleFormSubmit()
    {
    Console.WriteLine("Form Submitted Successfully!");
    FormModel.SelectedPerson = null; //I assume this is how you clear the typeahead?
    }
  3. Run sample and submit form. Text clears but placeholder text doesn't come back.

Expected behavior Placeholder text is restored when bound value is set to null.

Screenshots Expected: image

Actual: image

Hosting Model:

Additional context Add any other context about the problem here.

kamranghamsari commented 3 years ago

Same Here

kamranghamsari commented 3 years ago

@chrissainty no comment?

chrissainty commented 3 years ago

@kamranghamsari This requires some investigation and I don't have any free time for this right now. Feel free to look into it and propose a solution.

BadBlitz commented 3 years ago

@chrissainty I've had this same issue. With the latest update, it looks like the "Initialize" call was removed from the ParametersSet override. This is a problem when "Value" has been nulled out to reset the control and we need IsShowingMask moved back to false.

I'm still wrapping my head around this project, but the test for IsShowingMask on the single select could also test for Value != null. The other option it to make "HandleClear" public as proposed in #210 .

dsfridayslab commented 2 years ago

I had this issue as well. Not sure if the cause is the same, but when I experienced the issue, I was setting the bind-value property to a nullable string with string.Empty as the default value.

I fixed it by removing the default value, so the bound property is null and not empty string.