Blazored / TextEditor

Rich text editor for Blazor applications - Uses Quill JS
MIT License
277 stars 61 forks source link

Can´t reference Editor in OnAfterRender or OnParametersSet #34

Closed Sahara150 closed 3 years ago

Sahara150 commented 3 years ago

Hey, I pretty much copied your "Basic Example" of the TextEditor into my component. However, when I try to fetch the Text from the Editor in "OnAfterRenderAsync" it always throws following error:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Unable to get property 'getText' of undefined or null reference TypeError: Unable to get property 'getText' of undefined or null reference at window.QuillFunctions.getQuillText

which seems pretty weird to me. I checked, if you initialized your Editor somewhere, but could not find anything. I am using Blazor WASM. Here´s my code: ` <Blazored.TextEditor.BlazoredTextEditor @ref="DescriptionEditor" >

//The content you had
        <EditorContent>
            @Model.Description
        </EditorContent>

</Blazored.TextEditor.BlazoredTextEditor>

@code {

[Parameter]
public ExtendedModel Model { get; set; }
BlazoredTextEditor DescriptionEditor;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    Console.WriteLine(await DescriptionEditor.GetText());
}

`

(Something weird happened to the formatting. Sorry for that...)

Sahara150 commented 3 years ago

So I checked the same stuff with your example and it also threw the error. It makes sense to me, that you cannot reference it in the OnInitialized-method, since the editor is not rendered there, yet. However above methods are called after rendering. Shouldn´t it work there?

ADefWebserver commented 3 years ago

Please see this for assistance: You can't load the text editor within the OnInitialized event. Is there another way?