Requirement
In my previous article, we discussed how to implement a custom JavaScript validation message. Now, let’s say we want to change the title of the validator.
Solution
To accomplish the above requirement, the first thing I tried to check was its element, using the inspect tool. This way, I can use jQuery to change this message, and here is what I got from the inspect tool.
You can see in the above screenshot that the div has the ValidationSummaryEntityFormControl_EntityFormView ID so I used the following code-
$('#ValidationSummaryEntityFormControl_EntityFormView').attr("aria-label", "Preferred appointment cannot be submitted due to the reasons below:");
However, I was not able to see any changes in the validation message and then, I tried to check again using inspect. I found that even though this label was changed, the validator title was the same.
Next, I tried the following code in the console.
$('h4.validation-header').text("Appointment preferences cannot be submitted due to the reasons below:");
And, I was able to see changes in the validation title as well, like the following.
But when I used this code under entity form and checked, it was still showing the old title. Finally, I found that the above heading element is generated at runtime only. So, finally, I was able to use a set interval method like the following.
// Change form validation label
setInterval(function () {
if ($('h4.validation-header')) {
$('h4.validation-header').text("Appointment preferences cannot be submitted due to the reasons below:");
}
}, 1000);
Hope it will help someone, feel free to share if you know the more efficient method to implement it.
Stay tuned for more Dynamics 365 content.