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: @onchange event not working on input with type="datetime-local" in some browsers

See original GitHub issue

Describe the bug

The “datetime-local” input type is currently only supported on Chrome and Edge. On browsers that don’t support it (e.g. Safari or Firefox on desktop) it gracefully degrades to a “text” type input. If I try to use the @onchange attribute on a supported browser this works fine and the method assigned to it is called when I make a change.

<input type="datetime-local" value=@dateTimeString @onchange=DateTimeChanged />

But if I try to use the @onchange attribute on this input in an unsupported browser, the method is not called and I get this error in the console.

Error: Invalid element type 'text'.

It seems like the error is coming from line 249 of EventForDotNet.ts. It’s expecting the element to be of type “datetime-local” since that’s what it was declared as, but the browser is providing it as type “text”. That’s my guess anyway.

To Reproduce

Here’s a minimalistic repro project. All relevant code is in the Index.razor file.

Exceptions (if any)

No exceptions in the IDE, just this error in the browser console.

Error: Invalid element type 'text'.

Further technical details

  • ASP.NET Core version: 3.1.6 (Blazor v3.2.1)
  • Include the output of dotnet --info:
.NET Core SDK (reflecting any global.json):
 Version:   3.1.302
 Commit:    41faccf259

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.15
 OS Platform: Darwin
 RID:         osx.10.15-x64
 Base Path:   /usr/local/share/dotnet/sdk/3.1.302/

Host (useful for support):
  Version: 3.1.6
  Commit:  3acd9b0cd1

.NET Core SDKs installed:
  3.1.200 [/usr/local/share/dotnet/sdk]
  3.1.202 [/usr/local/share/dotnet/sdk]
  3.1.300 [/usr/local/share/dotnet/sdk]
  3.1.301 [/usr/local/share/dotnet/sdk]
  3.1.302 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.17 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.18 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.19 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.20 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
  • The IDE (VS / VS Code/ VS4Mac) you’re running on, and it’s version: VS for Mac 8.6.6 Build 11.

  • I can reproduce this on both server-side Blazor and WebAssembly Blazor.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
craigbrowncommented, Jul 23, 2020

Yeah there is definitely an unfortunate lack of support in some browsers! The issue is that while these browsers “degrade gracefully”, Blazor doesn’t. Thanks for looking into it, hopefully this is something that can be easily fixed in future.

1reaction
mkArtakMSFTcommented, Jul 23, 2020

Thanks for contacting us. Support of datetime-local is somewhat problematic: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local

We will look into what can be done here in the future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

onChange event not firing Blazor InputSelect
The problem is the @bind attribute makes use of the @onchange event and Blazor will not allow multiple @onchange event handlers.
Read more >
ASP.NET Core Blazor event handling
Learn about Blazor's event handling features, including event argument types, event callbacks, and managing default browser events.
Read more >
Blazor Events and Data Bindings
The above code has an input type text tag which has an onchange event of Blazor. It calls a handler method called userName....
Read more >
Blazor: Working with Events
I cover two types of events, DOM events and custom or user-defined events. DOM events are things such as onclick or onchange and...
Read more >
Blazor MultiColumnComboBox - Events - Documentation
OnChange fires when the user presses Enter in the input, or blurs the input (for example, clicks outside of the combo box). It...
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