Coulmn Validation in Blazor,

When I use custom validations in Grids, I noticed that it gets stuck in breakpoint twice during debugging. When you use an API to control a field and fetch data from the database, this call happens twice, which is not interesting in terms of performance. Do you know any way to solve this problem?

https://blazor.syncfusion.com/documentation/datagrid/column-validation#custom-validation



Attachment: TEST_ca568981.rar

6 Replies 1 reply marked as answer

NP Naveen Palanivel Syncfusion Team December 4, 2024 02:13 AM UTC

Hi Sam,

We reviewed your query and it seems that when using custom validation, it appears to trigger twice. To resolve this issue, we recommend using the DataAnnotationValidator component, which ensures that the validation is triggered only once during custom validation. Please refer to the code snippet below for more details.

 

<SfGrid DataSource="EmployeeList" AllowPaging="true" Toolbar="toolbar">

    <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true">

        <Validator>

            <DataAnnotationsValidator></DataAnnotationsValidator>

        </Validator>

    </GridEditSettings>

    <GridColumns>



Please get back to us if you have any concerns.


Regards,

Naveen



SA Sam December 4, 2024 05:18 PM UTC

Hi Naveen 

Thank you for your kindness, yes your opinion is correct. I had tested both methods and noticed this bug and just wanted to let you know so that you are also aware and can fix it if needed.

Thank you



NP Naveen Palanivel Syncfusion Team December 10, 2024 02:50 PM UTC

Hi Sam,

Currently Validating the reported query at our end with high priority and we will update the further details within two days( 12th Dec, 2024). Until then we appreciate your patience.

Regards,
Naveen.



NP Naveen Palanivel Syncfusion Team December 14, 2024 04:32 AM UTC

Hi Sam,

We would like to inform you that the Grid uses two validator components by default to handle validation. These components are the DataAnnotationValidator, which handles validations based on data annotations, and Internal ValidationRules, which validates according to the rules defined in the grid’s ValidationRules property. The reason for the double trigger of validation is that both validators are executed during the validation process. As a result, the custom validation logic is triggered twice. This behavior is expected, as it ensures that both custom validation rules and annotation-based validations are respected.

Regards,
Naveen


Marked as answer

SA Sam December 14, 2024 05:28 AM UTC

Hi Naveen


Based on your explanation, it seems logical to enable validations twice


Best wishes to your team,

Sam



NP Naveen Palanivel Syncfusion Team December 17, 2024 01:48 AM UTC

Hi Sam,


Thank you for your understanding

Kindly get back to us if you have further queries. As always we will be happy to assist you.


Regards,

Naveen


Loader.
Up arrow icon