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
420
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.

Parents
No Data
Reply
  • 17590
    Offline posted

    Hello William,

    Thank you for posting in our community. 

    In order to ensure that your issue is addressed correctly I need some clarifications about your scenario. Let me see whether I understood correctly.

    You are looing for a way to validate  that newly entered "Widget" cell values do not match any of the previously entered values for "WidgetCode" column and also validate that this value matches the "siteID". Based on the condition failed you would like to set different text for the error message? 

    Please verify whether this is your requirement and I will investigate this matter further for you.

    Looking forward to hearing from you.

Children