We have an application that can trigger javascript functions on different events (like onBlur). The function simply got the id and an attribute _id for the element that triggered the event. For Chrome, event.target has suddenly stopped working and I suspect it has something to do with a recent change in Chrome: https://chromium.googlesource.com/chromium/src/+/dcfa1803d4408370e3b1a187b84d4a6b620f491a
onBlur__Invalid : function () {
// For Internet Explorer
if (window.navigator.userAgent.indexOf("MSIE ") > -1) {
var currentId = window.event.srcElement.getAttribute('_id');
var currentTarget = '#' + window.event.srcElement.id;
}
// For other browsers
else {
var currentId = event.target.getAttribute('_id');
var currentTarget = '#' + event.target.id;
}
// Show Hint-message if x-form-invalid
if (currentId.indexOf("date_") > -1 && $(currentTarget).hasClass('x-form-invalid')) {
$(currentTarget).parents().eq(5).next().addClass('is_invalid');
}
else {
$(currentTarget).parents().eq(5).next().removeClass('is_invalid');
}
if($(currentTarget).hasClass('x-form-invalid')) {
$(currentTarget).parent().next().addClass('is_invalid');
}
else {
$(currentTarget).parent().next().removeClass('is_invalid');
}
},
Do anyone know an alterantive to event.target that works with Chrome and this script, or see a reason for this script to simply stop working overnight? As soon as the script enters the else statement it fails and stops running. Adding a try/catch gives the following error: "TypeError: Cannot read property 'target' of undefined"
Edit: If I pass the attribute _id from the onBlur function call like this:
ca_fd.js.onBlur__Invalid("sel_1");
I have managed to get it working like this:
onBlur__Invalid : function (e) {
// Show Hint-message if x-form-invalid
var currentTarget= '\'input[_id="' + e + '"]\''
alert($(currentTarget).attr('id'));
if (e.indexOf("date_") > -1 && $(currentTarget).hasClass('x-form-invalid')) {
$(currentTarget).parents().eq(5).next().addClass('is_invalid');
}
else {
$(currentTarget).parents().eq(5).next().removeClass('is_invalid');
}
if($(currentTarget).hasClass('x-form-invalid')) {
$(currentTarget).parent().next().addClass('is_invalid');
}
else {
$(currentTarget).parent().next().removeClass('is_invalid');
}
},
The call used to be ca_fd.js.onBlur__Invalid();, so this means I have to add the _id manually in all elements in all forms in the form designer of the application. The alert will in this case return "x-auto-16".
Hopefully the application can pass the _id I need with a variable, but I have yet to find it. Adding event or _id just returns undefined.