I have a Customer object with a CountryCode property of type int that is used as foreign key for a Countries table.
The user is asked to select a country from a ComboBox, that I want to be initially empty.
When the page is loaded I create a Customer object, whose CoutryCode is set to 0, that means, no country code selected yet (in my Countries table I have no countries with Code = 0).
This is what happens to ComboBox text:
- If CountryCode has a matching row in Countries, then then country name is shown. This is ok.
-
If CountryCode has a no matching rows in Countries (this happens when CountryCode = 0), then CountryCode value ("0") is shown. This is bad: I would like the placeholder (or an empty box) to be shown when an invalid value is selected.
- If text is removed via keyboard then CountryCode is set to 0. This is ok.
In version 18 there used to be a text property in ComboBox that could be used force text content, but it sems it has been removed.
I'd like to stress that I'm aware that using int? instead of int for Customer.CountryCode will solve this issue. Unfortunately, this would impact other aspects of my code, so I cannot change this.
Thank you
Attachment: BlazorApp1_bee6429a.zip