Text Box focus with content selected

Hello

I am focusing a text box using MyTextBox.FocusIn().  If the textbox already contains text (its on an editform) is there a way to make the text in the text box pre-selected so that the user does not have to.  My text box currently looks like this when the editform opens (the cursor is at the end)



I want it to look like this:



When you tab through an edit form the text is pre-selected as above, just not on the first field.

Thanks



3 Replies 1 reply marked as answer

PM Ponmani Murugaiyan Syncfusion Team September 15, 2020 05:34 PM UTC

Hi Ditchford, 

Greeting from Syncfusion support. 

The requested requirement is achieved using JS interop since we could not access the DOM elements in the Blazor platform. We have achieved in created event, the same can also achieved in Focus event and attached the sample below for reference. 

[Index.razor] 

<SfTextBox ID="myText" @ref="textboxObj" Value="Syncfusion" Created="OnCreate"></SfTextBox> 
 
@code { 
    SfTextBox textboxObj; 
    [Inject] 
    protected IJSRuntime JsRuntime { get; set; } 
 
    public async Task OnCreate(object args) 
    { 
        await JsRuntime.InvokeVoidAsync("onClick", "myText"); 
    } 
} 

[Highlight.ts] 
 
window.onClick = (args) => { 
    document.getElementById("myText").select(); 
} 
 
 
Kindly check with the above sample meets your requirement. Please get back us if you need further assistance. 

Regards, 
Ponmani M 


Marked as answer

DI Ditchford September 17, 2020 12:58 PM UTC

Perfect...thanks


PM Ponmani Murugaiyan Syncfusion Team September 18, 2020 05:06 AM UTC

Hi Richard, 

Thanks for the update. 

We are glad to hear that the provided suggestion helped you in achieving  your requirement. Please get back us if you need further assistance. 

Regards, 
Ponmani M 


Loader.
Up arrow icon