Cursor position on FocusIn()

I'm using Blazor 18.4.0.43 + AspNetCore 5.0.2 and I need to use the FocusIn() function to set the cursor position over a SfMaskedTextBox.
The function works, but the cursor position is at the end 
How can I set it at the beginning ?
I found several solutions in this forum but all for Angular, React and so on but Blazor component 
Also the OnFocus() and the @onfocusin() events seems to be not fired even if the arguments in these functions doesn't seems to be helpful for this job

<GridColumn Field=@nameof(TrapdettagliDTO.TtrapOre) AutoFit="true">
   <EditTemplate>
      <SfMaskedTextBox @ref="Oremask" @onfocusin="onfocus" Mask="00:00" @bind-Value="(context as TrapdettagliDTO).TtrapOre"></SfMaskedTextBox>
   </EditTemplate>
</GridColumn>

private void onfocus(Microsoft.AspNetCore.Components.Web.FocusEventArgs args)
{
        
 }

3 Replies 1 reply marked as answer

BC Berly Christopher Syncfusion Team March 23, 2021 08:03 AM UTC

Hi Walter, 
  
Greetings from Syncfusion support. 
  
We have prepared the sample by defining Masked Textbox component with our OnFocus event which is triggered as expected in our end. Also, we can change the selectionStart and selectionEnd of the masked textbox component in the focus event with help of using JS interop in the Blazor platform. 
  
@using Syncfusion.Blazor.Inputs 
 
<SfMaskedTextBox ID="mask" @ref="Oremask" OnFocus="onFocus"  Mask="00:00" @bind-Value="TtrapOre"> 
</SfMaskedTextBox> 
 
@code{ 
    SfMaskedTextBox Oremask; 
    [Inject] 
    protected IJSRuntime JsRuntime { get; set; } 
 
    public string TtrapOre { get; set; } = "22:00"; 
    public void onFocus(Microsoft.AspNetCore.Components.Web.FocusEventArgs args) 
    { 
        JsRuntime.InvokeVoidAsync("onFocus", "mask"); 
    } 
} 
window.onFocus = (id) => { 
    var maskObj = document.getElementById(id); 
    maskObj.selectionStart = 2; 
    maskObj.selectionEnd = 2; 
} 
 
  
Output screenshot: 
  
 
  
  
Regards, 
Berly B.C 


Marked as answer

WM Walter Martin March 23, 2021 09:35 AM UTC

Thank you
your solution works fine




BC Berly Christopher Syncfusion Team March 24, 2021 03:52 AM UTC

Hi Walter, 
  
Most welcome. Please let us know if you need further assistance on this. 
  
Regards, 
Berly B.C 


Loader.
Up arrow icon