Grid Popup Marks All Fields as Required

1 Answer 62 Views
Grid
Matthew
Top achievements
Rank 1
Matthew asked on 24 Jun 2022, 04:26 PM
I have a grid with a custom popup editor.   All of the fields in the popup are automatically set to "Required" when the pop up opens.  There are no annotations in the model that should be causing them to be validated.  I only want a couple of them to be required.  How do I change this behavior?  Where is Kendo getting the idea that every field must be required?

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 29 Jun 2022, 12:59 PM

Hi Matthew,

Thank you for the provided information it is greatly appreciated. I am sorry to hear that you currently are experiencing difficulties.

The encountered behavior may be due to the default convention that is applied to the Grid. Under the hood, the Grid will initialize a Kendo Validator for the Popup's form. Underneath each field with validation, a span with "k-invalid-msg" class is added. This span is used to display the validation messages in a tooltip. You can notice this within the browser inspector:

With that being said, a possible approach would be to mark the desired fields as nullable in order to prevent the required validation. For example:

public class OrderViewModel
{
    public decimal? Freight
    {
        get;
        set;
    }
}
 This will result in the following result:

 

An alternative approach would be to manually handle the validation on the server side. We have a pretty comprehensive blog post that elaborates more on how the server-side errors can be handled in the Grid. The approach mentions:

  • Adding the desired errors to the ModelState.
  • Displaying the errors upon validation on the client-side.

It can be found here:

Please give these suggestions a try and let me know how it works out for you.

Best Regards,
Alexander
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Matthew
Top achievements
Rank 1
commented on 29 Jun 2022, 08:04 PM

That fixed it!  Thank you so much!
Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or