RadzenRequiredValidator not working on RadzenDropDown/DropDownDataGrid

Hello,

I have several Create/Edit forms generated with radzen. I added on some of them RadzenRequiredValidators to my DropDowns/DropDownDataGrid and in some cases they work and in others they do not. I have checked that everything is inside a RadzenTemplateForm and that the submit fuction is Ok and I did not found anything wrong. In some of those forms there are both TextBox and DropDowns and the TextBox Validate is working fine and the DropDown Validate is not.

Does someone have any idea on how to solve this problem?

Thank you.

Hi @Ruben_Agustin,

We haven't encountered this problem before. The RequiredValidator should work with DropDown/DropDownDataGrid.

Hi I have checked the code many times and I still do not see any errors.

The code:

The form:

I have also compared the .razor.designer.cs with the ones that are working and I do not see any difference that could make the validator not work.

What is the type of the PackagingId property?

The property PackagingId is an int

The int always has a value (0) which is why the required validator won't work (there is always a value). We will extend the CompareValidator to support comparison operators and you would be able to use it and compare if the value is not 0. We will add support for that in one of the future Radzen releases.

Now you will have to check if the value is not 0 when you Invoke the data source method (use the Condition property e.g. ${packaginggroupdetail.PackagingId != 0}

1 Like

Oh OK, that makes sense. I did not realize the ones that were working are type int? so that is why.

Thank you

With dropdowns with integer IDs, a simpler solution I have found is to replace the RequiredValidator with a NumericRangeValidator and set the Min value to 1.

This is working well for me

Hi, I just did that, but it still don't work.

<RadzenGridColumn Width="200px" TItem="TimekeepingTransactionViewModel" Property="EmployeeFullName" Title="Employee">
            <EditTemplate Context="TimekeepingTransactionViewModel">
                <RadzenDropDown @bind-Value="TimekeepingTransactionViewModel.EmployeeId" Data="@employeesViewModel" TextProperty="FullName" ValueProperty="EmployeeId" 
                                Style="width:100%" />
                <RadzenNumericRangeValidator Component="EmployeeId" Min="1" Max="10" Text="Employee is required" Popup=true Style="position: absolute" />
            </EditTemplate>
        </RadzenGridColumn>