JQuery 3.4.1 Cannot read property 'value' of undefined
Asked Answered
E

2

6

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

Escargot answered 12/2, 2020 at 13:30 Comment(1)
Can you please add the full code which creates the issue in to the questionSarsaparilla
Q
4

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.

Quack answered 12/2, 2020 at 13:51 Comment(0)
A
5

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

Antananarivo answered 12/2, 2020 at 13:42 Comment(1)
Yeah, you are right, but in my app I'm using blur and focus element to launch other behaviours as wellEscargot
Q
4

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.

Quack answered 12/2, 2020 at 13:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.