question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor: contenteditable and onblur throws InvalidOperationException

See original GitHub issue

I want to use a editable div in Blazor to mix plain text and some html-elements like <button>. I know that value-binding is not supported right now for editable divs so I want to use the onblur-event to read and parse the text.

But when I change the content and leave the div I get an InvalidOperationException.

This only occurs when I use a custom Tag like <Test MyParam… When I put the content of the <Test-Tag directly inside the div there is no error.

Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: TypeError: Cannot read property ‘ownerDocument’ of null System.InvalidOperationException: TypeError: Cannot read property ‘ownerDocument’ of null at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents) Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit ‘NnPSnUvIn1Wh1tNJYULIQVe_UmVkJcyxD7Aj5x80qV8’. System.AggregateException: One or more errors occurred. (TypeError: Cannot read property ‘ownerDocument’ of null) —> System.InvalidOperationException: TypeError: Cannot read property ‘ownerDocument’ of null at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents) — End of inner exception stack trace — The thread 0x14ff8 has exited with code 0 (0x0).

Here is a simple example to reproduce this issue:

<div contenteditable="true" style="border: 1px solid gray;" spellcheck="false" @onblur="OnBlur">
    <Test MyParam="@_part"></Test>
</div>

@code {

    private MyClass _part;

    protected override async Task OnInitializedAsync()
    {
        _part = new MyClass();
    }

    private async void OnBlur(FocusEventArgs args)
    {
    }

    public class MyClass
    {
        public string Id { get; set; }
    }
}





//this is the content of the Test.razor. the x is a sample content
x

@code {

    [Parameter]
    public Index.MyClass MyParam { get; set; }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
anthcoolcommented, May 8, 2020

I have since resolved my issue with this. It was me, not the framework. My bad. Thanks though!

image

image

image

image

0reactions
mkArtakMSFTcommented, Jul 28, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Blazor input: onblur throws, oninput works fine
Components.ChangeEventArgs'. This feels like it's the framework and not me. Any ideas? I am using blazor server in .net 5.0.
Read more >
Binding contentEditable div in UI for ASP.NET MVC
I have some divs in my page that have the contentEditable attribute. How can I update the viewmodel when the user changes the...
Read more >
inputtext blazor onchange
Blazor : contenteditable and onblur throws InvalidOperationException. Site design / logo 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA.
Read more >
HTMLElement: contentEditable property - Web APIs | MDN
The contentEditable property of the HTMLElement interface specifies whether or not the element is editable.
Read more >
Phx-blur with contenteditable - Questions / Help - Elixir Forum
I have been fighting with it for a few hours and I can find no way to get the value within the div...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found