1
0
mirror of synced 2025-03-10 22:56:12 +03:00

fix search field focussing problems. fixes #922

This commit is contained in:
Igor Vaynberg 2013-02-27 08:53:17 -08:00
parent 9c2170c64e
commit 83d77cfa62

View File

@ -229,20 +229,22 @@ the specific language governing permissions and limitations under the Apache Lic
$el.focus();
/* 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(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
/* make sure el received focus so we do not error out when trying to manipulate the caret.
sometimes modals or others listeners may steal it after its set */
if ($el.is(":visible") && el === document.activeElement) {
/* 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);
}