SelectAll

Good morning,

How can I select the text of a SfNumericTextBox after I call SfNumericTextBox.FocusIn()?
The first time I call FocusIn() the cursor goes to the final of the text and I have to use backspace to erase the old value.
I would like to now also how can I avoid an input component get focus after the tab key is pressed.

Thanks in advance!

1 Reply

BC Berly Christopher Syncfusion Team May 25, 2020 09:46 AM UTC

Hi Társis, 
  
Greetings from Syncfusion support.  
  
We could not access the DOM element in the Blazor platform. So, we can achieve the requested requirement by calling select method in the focus event with help of JS interop as mentioned below. 
  
Also, we can restrict the focus of the input element by pressing the TAB key by setting the TabIndex property as “-1”.  
  
[index.razor
@using Syncfusion.Blazor.Inputs 
 
<SfNumericTextBox @ref="numericObj" ID="numeric" TValue="int?" Value="232" TabIndex="-1"> 
    <NumericTextBoxEvents TValue="int?" Focus="OnFocus" Created="OnCreate"></NumericTextBoxEvents> 
</SfNumericTextBox> 
 
 
@code { 
    SfNumericTextBox<int?> numericObj; 
    [Inject] 
    protected IJSRuntime JsRuntime { get; set; } 
 
    public void OnCreate() 
    { 
        this.numericObj.FocusIn(); 
    } 
    public async Task OnFocus(NumericFocusEventArgs args) 
    { 
        await JsRuntime.InvokeVoidAsync("onFocus", "numeric"); 
    } 
} 
[wwwroot/focus.js
window.onFocus = (id) => { 
    var numericObj = document.getElementById(id); 
    numericObj.select(); 
} 
[_Host.html
  <script src="~/focus.js"></script> 

  
Please find the sample from the below link. 
  
Regards, 
Berly B.C 


Loader.
Up arrow icon