After upgrade jQuery 3.4.0 to 3.4.1, on blur()
or focus()
events on input I'm getting Cannot read property 'value' of undefined
error.
that.container.on('click', '.binary_field', function(){
$("input:focus").blur();
}
I think that may be cause of this change in jquery source code: https://github.com/jquery/jquery/commit/24d71ac70406f522fc1b09bf7c4025251ec3aee6?diff=unified#diff-031bb62d959e7e4949d1847c82507f33L579-R583
The “cannot read property of undefined” error occurs when you attempt to access a property or method of a variable that is undefined . You can fix it by adding an undefined check on the variable before accessing it.
Causes for TypeError: Cannot Read Property of Undefined In short, the value is not assigned. In JavaScript, properties or functions are Objects, but undefined is not an object type. If you call the function or property on such variable, you get the error in console TypeError: Cannot read undefined properties.
The "Cannot read property 'click' of null" error occurs for 2 reasons: Calling the click() method on a null value, e.g. a DOM element that doesn't exist. Placing the JS script tag above the HTML where the DOM elements are declared.
This is a known issue in jQuery 3.4.1:
https://github.com/jquery/jquery/issues/4417
Use the JavaScript .blur() instead of the jQuery method.
Your code seems good, there is a workaround in your case, remove jquery for this line.
You can replace
$("input:focus").blur()
by
document.activeElement && document.activeElement.blur()
// Test if there is a focused element, if yes remove the focus
or (with jQuery and VanillaJs)
$(document.activeElement)[0].blur()
// or
$("input:focus")[0].blur()
It's the same behavior
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With