Dropdown validation

Hi,

I am trying to validate my form with RadzenRequiredValidator but it is not working. I have one RadzenTextBox and two RadzenDropDowns. In first dropdown it is possible to select one string value and in second it is possible to select multiple string values. Selected value from first dropdown is binded to string type variable. Selected values from second dropdown are binded to EnumerableQuery type variable. For text box validation is working, it shows validation error message, but for dropdowns validation always passes even though nothing is selected. For both dropdowns I'm using variable of type IEnumerable to import values to them. I tried setting DefaultValue for RadzenRequiredValidator but it didn't help. Can someone help me?

Hi @leoog5,

Validation won't work unless you use @bind-Value.

Update: just pushed a demo showing how to use required validator with dropdowns (not yet live): radzen-blazor/RequiredValidatorDropDown.razor at master · radzenhq/radzen-blazor · GitHub

Hi,

I added @bind-Value and it works now. Thank you for your help.

For anyone wondering how to run logic when binding the value, use the Change method, not the ValueChanged or SelectedItemChanged methods.

Fairly obvious point I know, but you also need the ID values to be nullable types. So if your ID property is an Int, its default value is zero, so it doesnt invalidate. You need to set it to be an int?