Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
340
IGGrid RowEditDialog Custom Validation / Error Messages
posted

I am using the following to validate a field in the RowEditDialog.

columnKey: "Widget",
editorType: "text",
required: true,
valdation: true,
editorOptions: {
validatorOptions:
{
required: {
errorMessage: "You must enter a widget code to continue."
},
onblur: true,
custom:
function (ui, evt) {
var value = ui;
var rows = $("#widgetList").igGrid("rows");
for (var i = 0; i < rows.length; i++) {
var currentRow = rows[i];
var currentValue = $("#unitsList").igGrid("getCellValue", $(currentRow).attr("data-id"), "WidgetCode");

if (value.toString().toLowerCase() == currentValue.toString().toLowerCase() && $(currentRow).find(".ui-iggrid-editingcell").length == 0) {
console.log('existing unit code');
document.getElementById("errorMessage").value = "The unit code specified already exists.";
return false;
}
}
document.getElementById("errorMessage").value = "";

var siteId = document.getElementById("siteID").value;
if (!value.toString().toLowerCase().match(siteId.toLowerCase())) {
document.getElementById("errorMessage").value = "You must specify the widget Site ID in the unit code.";
console.log('wrong site id');
return false;
}

document.getElementById("errorMessage").value = "";
return true;
},
errorMessage:
function (arg) {
return document.getElementById("errorMessage").value;
}

}
}

I am using one custom method to validate two different things. I want to make sure the widget id does not already exist and I want to make sure the widget site id is correct.

I want the error message to read different things depending on what fails.Do I have to create two different custom methods, if so how do I do that? Or can I do what I am doing, is so how do I change the error message.

As you can see I have a bit of a hack where I set a hidden field to the error message then I call a function that gets the message, however this has proven to be unreliable. After the user corrects the first error, the message stays the same if the second condition fails.

Any help would be greatly appreciated.

Regards.