File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -229,20 +229,22 @@ the specific language governing permissions and limitations under the Apache Lic
229229
230230 $el . focus ( ) ;
231231
232- /* after the focus is set move the caret to the end, necessary when we val()
233- just before setting focus */
234- if ( el . setSelectionRange )
235- {
236- el . setSelectionRange ( pos , pos ) ;
237- }
238- else if ( el . createTextRange ) {
239- range = el . createTextRange ( ) ;
240- range . collapse ( true ) ;
241- range . moveEnd ( 'character' , pos ) ;
242- range . moveStart ( 'character' , pos ) ;
243- range . select ( ) ;
232+ /* make sure el received focus so we do not error out when trying to manipulate the caret.
233+ sometimes modals or others listeners may steal it after its set */
234+ if ( $el . is ( ":visible" ) && el === document . activeElement ) {
235+
236+ /* after the focus is set move the caret to the end, necessary when we val()
237+ just before setting focus */
238+ if ( el . setSelectionRange )
239+ {
240+ el . setSelectionRange ( pos , pos ) ;
241+ }
242+ else if ( el . createTextRange ) {
243+ range = el . createTextRange ( ) ;
244+ range . collapse ( false ) ;
245+ range . select ( ) ;
246+ }
244247 }
245-
246248 } , 0 ) ;
247249 }
248250
You can’t perform that action at this time.
0 commit comments