Field Custom Validation

Hello,

I ran into issue, where i don't know how to implement my own custom validations for grid fields. I only can use built in validations with built in messages. 

Query: Create own custom validations with custom messages. Replace built-in validation messages, for example: "This field is required", with my own messages.




Thanks in advance

1 Reply

SE Sathyanarayanamoorthy Eswararao Syncfusion Team March 26, 2018 04:58 PM UTC

Hi Domantas, 

Thanks for contacting Syncfusion support. 

Query: Create own custom validations with custom messages. Replace built-in validation messages, for example: "This field is required", with my own messages. 
 
We have achieved your requirement with the use of customValidation feature of the Grid control in the below example. Please refer the below code example. 


 
[gridcomponent.html] 
 
<ej-grid id="Grid" [dataSource]="gridData" allowPaging="true" [toolbarSettings]="toolbarItems" [editSettings]="editSettings" > 
    <e-columns> 
        <e-column field="OrderID" [isPrimaryKey]="true" headerText="OrderID" ></e-column> 
        <e-column field="CustomerID" headerText="CustomerID" [validationRules]= "{customregex: true }"></e-column> 
         
                    ….. 
 
   </e-columns> 
</ej-grid> 
 
[gridcomponent.ts] 
export class GridComponent { 
                                  …..   
 
  constructor() { 
 
    $.validator.addMethod("customregex", function (value, element, params) { 
        if (element.value.length > 1) 
            return true; 
        return false; 
}, "OrderID value is mandatory"); 
 
    this.gridData = window.gridData; 
    this.editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true }; 
    this.toolbarItems={ showToolbar : true, toolbarItems : ["add", "edit", "delete", "update", "cancel"]}; 
} 
} 

Refer the below screenshot 

 

Please refer the below documentation for more details of customValidation feature. 


Regards, 
Sathyanarayanamoorthy

Loader.
Up arrow icon