Get HTML text by sending a message by pressing enter

Hey guys, I have a question (:


We build a comment section in our application with your RTE and it's working great so far, but:

Is there a way to get the Markup of the RTE at any point with a call? We know that ValueChanged gets called OnBlur and that we can configure a SaveInterval and can use AutoSaveOnIdle, but our problem is that our users should be able to send a message by pressing enter, so they don't unfocus the RTE by pressing anywhere else.

We can't use a very low SaveIntverval like 1ms, because it causes a very high network usage (we don't know why) in our application. The Windows ResourceMonitor says, that the receiving bits are raising from 1000 B/s up to >50.000 B/s by just clickling in the RTE when we use SaveInterval="1" with no AutoSaveOnIdle.  

If we use AutoSaveOnIdle with a Delay like 10 ms, if someone types and presses Enter immedeatly, we don't have the whole text while sending the message (we need the Markup, the plain text we get by _editor.GetText() is not what we need). 

Is there any way to access the Markup with a call? _editor.GetXhtml() doesn't help here (We receive the last saved value). Do you have any suggestions?

Btw: When writing in the RTE and then disabling the RTE with e.g. Enter, the RTE gets disabled but I am still able to write in it, because I never loss focus. :P

Best regards,

Patrick


3 Replies

RK Revanth Krishnan Syncfusion Team June 22, 2021 01:41 PM UTC

Hi Patrick, 
 
 
Greetings from Syncfusion support. 
 
 
We have validated your query “Is there a way to get the Markup of the RTE at any point with a call? Our problem is that our users should be able to send a message by pressing enter, so they don't unfocus the RTE by pressing anywhere else.” 
 
Your requirement can be achieved by using the key down event for the div tag wrapper for the Rich Text Editor and then using the ‘JsInterop’ concept to retrieve the current Rich Text Editor value. We have prepared a sample for your reference, 
 
Code Snippet: 
_Host.cshtml 
<head> 
    . . . 
    <script src="~/jsinterop.js"></script> 
</head> 
 
Jsinterop.js 
window.RichTextEditor = { 
    getValue: function (id) {         
        var rteInstance = document.getElementById(id).blazor__instance; 
        // Retrieve the current Rich Text Editor value. 
        return rteInstance.getInputInnerHtml(); 
    } 
} 
 
Index.razor 
@using Syncfusion.Blazor.RichTextEditor 
<div @onkeydown="@onEnterClick" @onkeydown:preventDefault="@isPreventKey">     
    <SfRichTextEditor @ref="@rteObj" @bind-Value="@this.rteValue"> 
    </SfRichTextEditor> 
b</div> 
 
@code { 
    [Inject] 
    IJSRuntime JsRuntime { get; set; } 
 
    SfRichTextEditor rteObj; 
    public string rteValue { get; set; } 
    private bool isPreventKey { get; set; } 
 
 
    public async Task onEnterClick(KeyboardEventArgs args) 
    { 
        this.isPreventKey = false; 
        if (args.Key == "Enter" && args.Code == "Enter") 
        { 
            this.isPreventKey = true; 
            //Method called on enter key press. 
            string result = await JsRuntime.InvokeAsync<string>("RichTextEditor.getValue", this.rteObj.ID); 
        } 
 
    } 
} 
 
 
Please check the above code snippet and the sample and let us know if it satisfies your requirement. 
 
Regards, 
Revanth 



UN Unknown June 23, 2021 11:43 AM UTC

That's exactly what i was looking for! Thank you very much! Great support!



RK Revanth Krishnan Syncfusion Team June 24, 2021 12:35 PM UTC

Hi Patrick, 
 
Thanks for the update. 
We are glad that the provided solution satisfied your requirement. Please let us know if you need further assistance. 
 
Regards, 
Revanth 


Loader.
Up arrow icon