Issue with [Required] Validation

Hi Guys,

can you please help with what might be the problem here?

Below is a datagrid with validation on the columns for [Required} but hopefully you can see from the screen shot that there is definitely data in the edit fields.



the columns are declared as below

<GridColumn Field=@nameof(AddEditServiceDTO.Id)
                    HeaderText="ID" IsPrimaryKey="true" Visible="false"
                    Width="50" MinWidth="50" MaxWidth="50">
        </GridColumn>
        <GridColumn Field=@nameof(AddEditServiceDTO.Code)
                    HeaderText="Code"
                    Width="100" MinWidth="100" MaxWidth="100"
                    ValidationRules="@(new ValidationRules{ Required= true, MaxLength=DTOLibrary.DbFieldLengths.Services.Code })">
        </GridColumn>
        <GridColumn Field=@nameof(AddEditServiceDTO.Description)
                    HeaderText="Description"
                    ValidationRules="@(new ValidationRules{ Required= true, MaxLength=DTOLibrary.DbFieldLengths.Services.Description })">
        </GridColumn>

and the AddEditDTO class is defined as

public class AddEditServiceDTO
  {
    public int Id { get; set; }
    public string Code { get; set; }
    public string Description { get; set; }
  }

So I am not 100% sure what I have done differently to the examples, except that I am capturing the OnActionBegin event to add and save the records

thanks,
Jeremy








4 Replies 1 reply marked as answer

JE Jeremy December 2, 2020 10:27 AM UTC

I think I found what the difference is, in my code I have declared the following in my grid

 <GridEvents TValue="AddEditServiceDTO" OnActionBegin="OnActionBegin"></GridEvents>

then implemented the handler like so

 public void OnActionBegin(ActionEventArgs<AddEditServiceDTO> arg)
  {
    //Handles add operation
    if (arg.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Add))
      arg.Data = new AddEditServiceDTO() { Code = "", Description = "" };
  }


If I remove the code above (ie done create the new object as part of the Add action, the validation works as expected. 

So I am wondering what else do I need to do to use the above architecture and still have the validation work please?





RN Rahul Narayanasamy Syncfusion Team December 3, 2020 01:02 PM UTC

Hi Jeremy, 

Greetings from Syncfusion. 

Query: Issue with [Required] Validation  

We have validated your query and prepared a sample based on your shared code snippets for checking the reported problem. We could not reproduce the reported problem at our end. The validation messages only shown when the condition applied. Find the below sample for your reference. 


If you are still facing the problem, then could you please share the below details. It will be helpful to validate and provide a better solution. 

  • Full Grid code snippets.
  • Syncfusion NuGet version details and visual studio version details.
  • Reproduce the reported problem in the provided sample and revert back to us.
  • Share a simple reproduceable sample if possible.

Regards, 
Rahul 


Marked as answer

JE Jeremy December 6, 2020 09:56 AM UTC

Hi Rahul,

thanks for the sample. I worked my way through it and found the the difference was that your grid model class had a constructor and mine didnt. 

I updated my model class to have a constructor and the grid validation is working as expected thankyou.

Regards,
Jeremy


RN Rahul Narayanasamy Syncfusion Team December 7, 2020 04:36 AM UTC

Hi Jeremy, 
 
Thanks for the update. 
 
Please get back to us if you need further assistance. 
 
Regards, 
Rahul 


Loader.
Up arrow icon