Is there an alternative to InputText._selectAllText()?

Hi,

In my application, I need to programmatically select all text inside an InputText control. I searched the API, but I could only find InputText._selectAllText(), which is a protected method.

When I invoke the method, ignoring the visibility, it seems to work as expected.

Is there an alternate way to select the content of an InputText? Or should I open a feature request to change the visibility of _selectAllText()?

Thanks!

Hello :slight_smile:

An trick would be to set onFocusSelectAll to true, and trigger a focus :

NB: the initial input.blur() is here is case you are already focused when the select is called, so that the onFocusSelectAll is still triggered

Thanks, but it doesn’t help in my case since the text changes after the control gets a focus. Initially, the value is a 3-digit number like “100”, but if it changes to something like “1468”, only the first “146” gets selected.

What are you trying to achieve exactly ?

If you are programmatically changing the text, you can still select afterward :

It’s a design program in which you can draw a wall by clicking the start and end points, during which you can also directly enter the desired length of the wall. The length of the wall changes as the user moves the pointer.

I admit my requirement might be rather unusual. But I don’t see why selectAllTexts can’t be made public when most other GUI libraries I know support a similar functionality. Thanks for the suggestion. But honestly, I feel toggling the focus seems to be a more of a hack than the one I applied, which is ignoring the visibility and just invoking the method anyway.

Maybe it can :slight_smile:

I guess it has been made private originally to be handled by shortcuts such as CTRL+A but now that you ask… You can make suggestion to have more public control on it, for sure !

I don’t know if you have tried my Babylon Chat but I have had other issues with GUI Inputs, and for sure there is room for improvement :wink:

1 Like

Then I’ll open a feature request now. :slightly_smiling_face:

Edit: Done!

1 Like

Hum? I agree it is. But it’s not the dirtiest hack we have ever made regarding the BJS GUI :face_with_hand_over_mouth: :grin:

I don’t think so. Looks legit to me.

I shall upvote this for the principle. Not sure what it implies. The hack seems doable to me. But I’m no dev, as long as it works, that’s good enough for me :grin:

1 Like