I just started using Radzen components for my Blazor Server Side app. I found out that there are very few information regarding the title above and how to properly fix or implement validations.
So i listed below what should be the correct implementation on the most common components.
So what is the correct way of using Radzen Validators?
Now, let us say you already completed the two items mentioned above and still the validations are not working properly.
Yes, you read it right. Using @bind-Value will fix all of my problems for components below:
Below are the examples:
For RadzenDatePicker: (below is using Inline Calendar, if you are not using the inline Calendar then you should validate the control the same as RadzenTextBox validation)
If your DateTime property is nullable then you should declare
DefaultValue="null".If your property is not nullable then you can specify the default value yourself. Example:
DefaultValue="DateTime.Min".For RadzenTextBox:
As you can see, the default value for any textbox is string so by default we do not need to define:
TValueandDefaultValueFor RadzenNumeric:
On this example, we want our component to accept values greater than or equal to 0. To validate,
@ValueIntPropshould be in nullable type andTValueshould also be in nullable type :private int? ValueIntProp { get; set; }andTValue="int?"andDefaultValue="null"With this validation, it will check if the current value is null, if the User try to submit the form then it will show the validation error
Finally:
Example:
For more info, read the documentations below:
Let me know on the comments if you have any questions or other suggestions