chebyr
January 7, 2020, 11:10am
1
HI I am trying to validate for required value selected in dropdown but does not seem to be working for me
<RadzenDropDown Data="@controlClassifications " TextProperty="Classification" ValueProperty="ClassificationId" @bind-Value="@((newControl.ClassificationId))" Name="Class" />
RadzenRequiredValidator Component="Class" Text="Classification is required" />
Any suggestions are appreciated
Thank you
2 Likes
Hi @chebyr ,
Did you put the DropDown and RequiredValidator inside a RadzenTemplateForm component? Radzen validators work only inside a RadzenTemplateForm.
chebyr
January 8, 2020, 4:34pm
3
yes I have
RequiredValidator works for textboxes but does not work for dropdowns
Hi, I have the same problem. How I can validate DropDown. Thanks
Check the type for binding value.
If it integer, validation will be always sucseeded.
It must be nullable type
2 Likes
You can set the DefaultValue property of the RequiredValidator - it specifies the value which should check against - using 0 for a numeric should work. Of course if 0 is a valid value you would need a nullable property as suggested by @Simon_Postford .
5 Likes
Thanks for tips. On the end I set default value to object, and then the drop down does not contains empty value.
Using RBS the RadzenRequiredValidator is not working for a dropdown component where the value property is a uniqueidentifier...
<RadzenFormField Text="Application" Variant="Variant.Filled">
<ChildContent>
<RadzenDropDown Data="@applicationsForApplicationId" TextProperty="Name" ValueProperty="ApplicationId" AllowClear=true
@bind-Value="@permission.ApplicationId" Name="ApplicationId" Style="width: 100%" />
</ChildContent>
<Helper>
<RadzenRequiredValidator Component="ApplicationId" Text="Application is required" />
</Helper>
</RadzenFormField>
Hi @semafox ,
It won't work as Guids have a default value (Guid.Empty). Try setting the DefaultValue attribute of RadzenRequiredValidator to Guid.Empty
:
<RadzenRequiredValidator DefaultValue=@(Guid.Empty) ... />
Thank you, that was the solution!