fix search field focussing problems. fixes #922
This commit is contained in:
parent
9c2170c64e
commit
83d77cfa62
28
select2.js
28
select2.js
@ -229,20 +229,22 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
$el.focus();
|
$el.focus();
|
||||||
|
|
||||||
/* after the focus is set move the caret to the end, necessary when we val()
|
/* make sure el received focus so we do not error out when trying to manipulate the caret.
|
||||||
just before setting focus */
|
sometimes modals or others listeners may steal it after its set */
|
||||||
if(el.setSelectionRange)
|
if ($el.is(":visible") && el === document.activeElement) {
|
||||||
{
|
|
||||||
el.setSelectionRange(pos, pos);
|
|
||||||
}
|
|
||||||
else if (el.createTextRange) {
|
|
||||||
range = el.createTextRange();
|
|
||||||
range.collapse(true);
|
|
||||||
range.moveEnd('character', pos);
|
|
||||||
range.moveStart('character', pos);
|
|
||||||
range.select();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* after the focus is set move the caret to the end, necessary when we val()
|
||||||
|
just before setting focus */
|
||||||
|
if(el.setSelectionRange)
|
||||||
|
{
|
||||||
|
el.setSelectionRange(pos, pos);
|
||||||
|
}
|
||||||
|
else if (el.createTextRange) {
|
||||||
|
range = el.createTextRange();
|
||||||
|
range.collapse(false);
|
||||||
|
range.select();
|
||||||
|
}
|
||||||
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user