Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Setting selectionStart on an element appears to do nothing. #12493

Closed
cuzzo opened this issue Aug 22, 2014 · 11 comments
Closed

Setting selectionStart on an element appears to do nothing. #12493

cuzzo opened this issue Aug 22, 2014 · 11 comments
Labels

Comments

@cuzzo
Copy link

cuzzo commented Aug 22, 2014

Hey,

I have an element:

var $el = document.getElementsByTagName("input")[0];

When I set the selectionStart attribute on $el it appears to do nothing--or remain whatever the length of text inside the input is.

$el.value = "ABC"
$el.selectionStart = 1;
console.log($el.selectionStart);

That outputs 3 for me.

I've tried this in a bunch of different contexts, and in every way it seems that the selectionStart is always the length of the element's value.

$el.value = "ABCD";
$el.setSelectionRange(1, 1);
console.log($el.selectionStart);

4

Thanks,

@jamie-pate
Copy link

I am also encountering this exact problem: PhantomJS 1.9.8 (Linux)

@omgaz
Copy link

omgaz commented Dec 3, 2014

👍 PhantomJS 1.9.8 (Mac OS X)

@wilandrade
Copy link

Also seeing it on PhantomJS 1.9.8 (Mac OS X)

@pontusi
Copy link

pontusi commented Mar 4, 2015

I have a similar but not identical problem.

From what I can tell, WebKit - at least the version embedded in PhantomJS - does not update the selection unless the control is added to the page and can be rendered. For my needs, all I need to do is add the control to the page.

var textbox = document.createElement('input');
document.body.appendChild(textbox); // This is critical for selectionStart/end to be updated.

textbox.value = 'test';
textbox.setSelectionRange(0, 4);

expect(textbox.selectionStart).toBe(0);
expect(textbox.selectionEnd).toBe(4);

As Op's control is already added to the page I'm not sure why it's not getting updated. It may be hidden by CSS.

@japgolly
Copy link

japgolly commented May 5, 2015

This is still a problem in PhantomJS 2.0.

@hellosmithy
Copy link

I'm seeing the same behaviour in both PhantomJS 1.9.8 and 2.0.2
Is there any likely fix on the horizon?

@oigewan
Copy link

oigewan commented Feb 18, 2016

Phantom 2.1.2 still has the issue.

@gbedardsice
Copy link

Not seeing the issue on 2.1.1 (Mac OS X), but issue occurs on 2.1.1 (Linux).

@dirkluijk
Copy link

Having the same issue on 2.1.1 (Windows).

@jamie-pate
Copy link

It appears to work when I create an input but don't add it to the dom. When I add it to the DOM it stops working.. (sometimes!)

These tests that rely on this are also failing on the linux build node, but succeeding on my linux desktop. Both are running PhantomJS 2.1.1 (Linux 0.0.0) 😖

@stale stale bot added the stale label Dec 26, 2019
@stale
Copy link

stale bot commented Dec 29, 2019

Due to our very limited maintenance capacity, we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed (see #15395 for more details). In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!

@stale stale bot closed this as completed Dec 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

10 participants