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.
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.
I was just thinking, the same way I can do [required: true], can I do [unique: true]? just curious.
That is correct. I want to validate two conditions in a custom validator and have two different errorMessages for each. Can I have two custom validators, if so how? If not how can I change the error message depending on the condition hat failed?