function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JuuanGallegosJuuanGallegos 

How do I can select the content of an input text field?

I'm trying to select all the text inside of an input text field, once a user fired an onfocus event, I tried using select() js method, but look like is not posible in lightning components, so there are someone to know how can I do it?

var inputSelected = component.find('inputId');
      inputSelected.select();
this is something that I'm trying to do it.

Thanks,

Juan Gallegos
 

Raj VakatiRaj Vakati
try like below 

 
var inputSelected = component.find('inputId').get("v.value");


 
Raj VakatiRaj Vakati
var inputSelected = component.find("inputId").get("v.value");

 
JuuanGallegosJuuanGallegos
Hi Raj thanks for response, I've already tried and doesn't work, the problem is with the select() method, I don't know why is not working, can be something related with bundle version settings? 
 
Raj VakatiRaj Vakati
Can you give me code for UI and JS controller to see the issue 
JuuanGallegosJuuanGallegos
UI:

<lightning:input name="input" id="test" aura:id="inputId" type="number" formatter="currency" value="{!v.product.inputTest}" onfocus="{!c.selectDataInInput }"  />

Controller:

selectDataInInput : function(component, event, helper){
       
        helper.selectDataInInput(component,event);
     
    }

Helper:

selectDataInInput : function(component,event){
       var inputSelected = event.getSource().getElement();
       inputSelected.select();
       
    },