Cannot access blazor__instance from JS

Hey guys!

We updated our applications a few versions to 19.4.52 and we getting error when accessing the blazor instance of the richtexteditor in JavaScript. 

this code:

var rteInstance = document.getElementById("defaultRTE").blazor__instance;

returns undefined - even if a have a defaultRTE id linked to the RTE in the mark up. Any ideas? did i miss something in the patch notes?


I attached a small example project.


Best Regards

Patrick


Attachment: RichTextEditor_Test_8c75608.zip

2 Replies

BS Buvana Sathasivam Syncfusion Team February 23, 2022 07:09 PM UTC

Hi Patrick, 
 
Currently, we are validating your reported query. We will update you the further details in two business days on or before February 25, 2022. 
 
Regards, 
Buvana S 



BS Buvana Sathasivam Syncfusion Team February 25, 2022 01:56 PM UTC

Hi Patrick, 

Thank you for your patience. 
You can achieve your requirement to set the cursor position at a specific node without using blazor_instance in the below way. In the below code, we set the cursor position at specific nodes using the jsinterop.js file. 
Index.razor 
  public async Task addContent() 
    { 
        rteValue = "<p id='id2' class='e-custom-class'>Hello</p>" + rteValue; 
    } 
 
    protected override Task OnAfterRenderAsync(bool firstRender) 
    { 
        JsRuntime.InvokeAsync<string>("RichTextEditor.setCursorPointer", "id2"); 
        return base.OnAfterRenderAsync(firstRender); 
    } 

jsinterop.js 
window.RichTextEditor = { 
    setCursorPointer: function (id) { 
        var RTEelement = document.getElementById('defaultRTE'); 
        var element = RTEelement.querySelector("#" +id); // Get the element 
        var range = document.createRange(); 
        var selection = document.defaultView.getSelection(); 
        range.setStart(element, 0);  // setStart range 
        range.collapse(true); 
        selection.removeAllRanges();  // Remove all ranges 
        selection.addRange(range);  // set the cursor position for addRange 
    } 
} 


Please let us know if you have any concerns. 

Regards. 
Buvana S 


Loader.
Up arrow icon