Validation Error Messages not displayed on Dialog if Field is not a column on Grid

Hello,

I've attached the code to replicate the error as detailed in the Subject, and the image to show the error. 

The code is generated by performing the following steps:
1. Copy the code from https://blazor.syncfusion.com/documentation/datagrid/editing/#dialog-template
2. Annotate [Required] for ShipCountry and ShipAddress Fields. Notice that there's a GridColumn to display ShipCountry, but not for ShipAddress.

Perform the following steps to replicate the bug:
1. Click "Add" to open the Dialog.
2. Click "Save".

Expected Result: Both ShipCountry and ShipAddress Fields display the validation error messages.
Actual Result: Only ShipCountry displays the validation error message.

You can also verify that annotating [Required] on other Fields that have a corresponding GridColumns, will also display the validation error messages.

The attached code is running Blazor Wasm .NET 5 RC 2, Syncfusion 18.3.42, the error is in Index.razor.

Attachment: error_message_not_showing_add77888.zip

5 Replies

ZY Zhi Yuan October 29, 2020 11:55 PM UTC

Hello,

Any updates? Thanks! :)


JP Jeevakanth Palaniappan Syncfusion Team November 3, 2020 06:54 AM UTC

Hi Zhi, 

Greetings from Syncfusion support. 

We have validated your query and for grid validation we have to define the column which is the default behaviour and so we suggest you to define the grid column with width as 0 to resolve your issue. Please find the below code snippet for your reference. 

</SfGrid> 
    <GridColumns> 
       <GridColumn Field=@nameof(OrdersDetails.ShipCountry) HeaderText="Ship Country" Width="150"></GridColumn> 
        <GridColumn Field=@nameof(OrdersDetails.ShipAddress) HeaderText="ShipAddress" Width="0"></GridColumn> 
    </GridColumns> 
</SfGrid> 

Please get back to us if you have any concern. 

Regards, 
Jeevakanth SP. 



ZY Zhi Yuan November 3, 2020 09:39 PM UTC

Hi Jeevakanth,

Thanks! However, setting the Width to 0 for the purpose of showing error messages seems rather unintuitive and so it's not helpful in terms of code maintainability. Will there eventually be a better solution?


JP Jeevakanth Palaniappan Syncfusion Team November 5, 2020 01:02 PM UTC

Hi Zhi, 

We are checking the feasibility and other possible solutions for your scenario. So we will update the further details on 6th  November 2020. Until then we appreciate your patience 

Regards, 
Jeevakanth SP. 



JP Jeevakanth Palaniappan Syncfusion Team November 6, 2020 01:18 PM UTC

Hi Zhi, 

Thanks for your patience. 

We suggest you to use the form validation if you want to show validation for the columns not defined in the grid. You have use the latest syncfusion NuGet version(18.3.0.47) to use the below code. 

@using System.ComponentModel.DataAnnotations 
 
<SfGrid DataSource="@GridData" Toolbar="@(new string[] {"Add", "Edit" ,"Delete","Update","Cancel" })"> 
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="@EditMode.Dialog"> 
        <Validator> 
            <DataAnnotationsValidator></DataAnnotationsValidator> 
        </Validator> 
        <Template> 
            @{ 
                var Order = (context as OrdersDetails); 
                <div> 
                    <ValidationMessage For="() => Order.ShipCountry" /> 
                    <ValidationMessage For="() => Order.ShipAddress" /> 
.. 
.. 
.. 
                <div> 
            } 
        </Template> 
    </GridEditSettings> 
</SfGrid> 

We have prepared a sample for your reference. Please download it from the below link. 

Please get back to us if you need further assistance. 

Regards, 
Jeevakanth SP. 


Loader.
Up arrow icon