royale-asjs icon indicating copy to clipboard operation
royale-asjs copied to clipboard

unable to use TextArea.setSelectionRange(0,0)

Open sanjeev-rajput opened this issue 7 months ago • 2 comments

i am unable to use setSelectionRange(0,0) on a textarea component tried on both jewel and spectrum

tried all these option input.text = ""; // Clear the box input.focus();// Set focus above two works fine

  1. input.element.setselectionRange(0, 0); // - NOT ACCEPTING
  2. document.getElementById("input").setSelectionRange(0, 0); // - NOT ACCEPTING
  3. var nativeInput:* = input.element as Object; if (nativeInput && nativeInput.setSelectionRange != null) { nativeInput.setSelectionRange(0, 0); }

tried all 3 options none works - plz suggest some

sanjeev-rajput avatar Jul 03 '25 11:07 sanjeev-rajput

@sanjeev-rajput Try input.element.focus()

piotrzarzycki21 avatar Jul 03 '25 11:07 piotrzarzycki21

@piotrzarzycki21 input.element.focus() is not the issue infect we don't have to use with element, it is working fine with input.focus().

allow me elaborate the use case

  1. user type in a textarea
  2. hit enter
  3. textarea is set to blank using input.text=""
  4. focus set to textarea using input.focus()
  5. user can start typing again - now here when a user press enter, cursor goes to the next line as the default behavior of textarea but we want to remove this next line and cursor set to the 0,0 position

sanjeev-rajput avatar Jul 04 '25 03:07 sanjeev-rajput