0

how to make a form invalid if a grid(DxDataGridModule) of DevExtreme framework doesn't have any row?

the grid is in row editing mode so the status of the myFormVariable.form.valid should change if i add or remove rows to the grid

<form  #myFormVariable="ngForm" id="frm_create_user" novalidate (ngSubmit)="save()">
.....
...
</form>
pinale
  • 2,060
  • 6
  • 38
  • 72

1 Answers1

0

I presume this save() method is called after the form was deemed valid. In this method simpy check if the grid is empty and report an error to the user.

function save(){
   var gridData = $("#grid").dxDataGrid().dxDataGrid("instance").option("dataSource");
   if(gridData == null || gridData.length == 0)
   {
      //Report the error to the user
      return;
   }
   //Code that issues a request to the server
}

I made a quick example on CodePen. I have copied the example from here and adjusted it so a grid is also present. This is just to give you a general idea of how to do.

Robert
  • 2,407
  • 1
  • 24
  • 35