- Home
- Forum
- ASP.NET MVC - EJ 2
- Custom validation message in Dialog
Custom validation message in Dialog
Hi,

Also - how do I write back several values from a dialog that only has 1 field visible to the table. I have done my ajax request to the server and I have the information I want to be populated in the table. For example, what object do I need to set (and when; grdRolesActionBegin or actionComplete) for hidden fields (eg company name) to show up in the table.
I have a grid with the below setup:
When I click the "Add" buttton I get the default Dialog showing up, and I have managed to hide all the fields except for Username using ActionBegin and ActionComplete methods.
Here's my struggle...
When the user clicks the save button I need to do an ajax request back to the server which will be able to return an error message in its response. Is there a way I can display a custom error / validation message on the Dialog after the ajax request?
Also - how do I write back several values from a dialog that only has 1 field visible to the table. I have done my ajax request to the server and I have the information I want to be populated in the table. For example, what object do I need to set (and when; grdRolesActionBegin or actionComplete) for hidden fields (eg company name) to show up in the table.
SIGN IN To post a reply.
1 Reply
1 reply marked as answer
PG
Praveenkumar Gajendiran
Syncfusion Team
May 11, 2021 01:34 PM UTC
Hi Neil,
Greetings from Syncfusion support.
We have prepared a sample based on your requirement. Please check the below code example and sample for more information on this.
In the below sample, we have bind the custom validation for EmployeeID column, send the AJAX post, validate the ID value in server and return the result(true or false). Finally we have changed the validation message content based on ajax return value inside the custom validation function itself. This is demonstrated in the below code example.
Greetings from Syncfusion support.
We have prepared a sample based on your requirement. Please check the below code example and sample for more information on this.
In the below sample, we have bind the custom validation for EmployeeID column, send the AJAX post, validate the ID value in server and return the result(true or false). Finally we have changed the validation message content based on ajax return value inside the custom validation function itself. This is demonstrated in the below code example.
|
<div>
<ejs-grid id="Grid" toolbarClick="toolbarClick" dataSource="@ViewBag.datasource" load="load" toolbar="@(new List<string>() { "Add","Delete","Update", "Cancel" })" allowPaging="true">
<e-grid-editSettings allowDeleting="true" allowEditing="true" allowAdding="true"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" validationRules="@(new { required=true})" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="EmployeeID" headerText="ID" width="170"></e-grid-column>
…….
</e-grid-columns>
</ejs-grid>
</div>
<script>
var value;
var validationflag = false;
var updatebuttonflag = false;
var saveflag= false
var rfinal = false;
function load() {
this.columns[1].validationRules = { required: true, minLength: [customFn, 'Checking....'] };
}
function toolbarClick(args) {
if (args.item.text == "Update") {
updatebuttonflag = true //enable when update toolbar button click
}
}
function customFn(args) {
let finalvalue = parseInt(args['value'], 10);
if (saveflag) {
saveflag= false
return true;
}
if (validationflag == true) {
rfinal = true;
validationflag = false;
} else {
rfinal = false;
let ajax = new ej.base.Ajax("/Home/getStatus", "POST", true); // call API
ajax.send(JSON.stringify({ EmployeeID: finalvalue }));
// Then we change the validation message content based on ajax return value in the ajax.onSuccess function
ajax.onSuccess = function (data) {
var gridInstance = document.getElementById('Grid').ej2_instances[0] // Grid Instances
value = JSON.parse(data); // declaring the ajax return value
if (value.result === true) { // check the status
validationflag = true;
if (updatebuttonflag) {
//call endEdit method manually to save the value when the update toolbar button is clicked and ajax return value as “true” in setTimeOut function
setTimeout(() => {
var gridObj = document.getElementById("Grid").ej2_instances[0]; // Grid Instances
saveflag = true;
gridObj.endEdit();
}, 50);
updatebuttonflag= false
}
gridInstance.element.querySelector('form').ej2_instances[0].validate();// validating the form in ajax.onSuccess when the return value as “true”
} else {
if (gridInstance.element.querySelector('form').children[1]) {
// Here we change the validation inner tooltip message
gridInstance.element.querySelector('form').children[1].querySelector('.e-tip-content').innerText = value.customText
}
rfinal = false;
validationflag = false;
}
};
}
return rfinal;
};
</script>
-------------------------------------------------------------------------------------------------------------
[HomeController] public ActionResult getStatus([FromBody]OrdersDetails value) {
if (value.EmployeeID <= 5)
{
return new JsonResult(new { result = false, customText = "The value cannot be lower than 5" });
}
else if (value.EmployeeID >= 20)
{
return new JsonResult(new { result = false, customText = "The value cannot be higher that 20" });
}
else
{
return new JsonResult(new { result = true });
}
} |
Sample: https://www.syncfusion.com/downloads/support/forum/165257/ze/2921021541418434.zip
Note: “We would like to inform you that, this solution is not suited for multiple columns because this function will be called regressive due to validate the form manually.”
Please get back to us if you need further assistance.
Regards,
Praveenkumar G
Marked as answer
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
- Marked answer
-
NB Neil Baker
- May 7, 2021 09:54 AM UTC
- May 11, 2021 01:34 PM UTC