How can 'onblur' and similar events be supported?

asp.net-core blazor c#

Question

I want to do something like:

<td contenteditable=true @onblur(async (txt) => { ... })>

but currently it seems only @onchange is supported, and doesn't actually fire when contenteditable content is changed. I suppose the method would be to have a JS handler that calls the C# handler, but I don't know if communication can go this way. Is the best option now just to have a button that has an onclick handler of 'save to DB'? Or is there a better option available?

Accepted Answer

You are correct, the current version of Blazor doesn't support the onblur event. Only the onclick, onchange and onkeypress events are supported. I believe this pull request should allow access to more events and should be in the 0.2.0 release.

You can call C# methods from JavaScript if you wanted to go this route. See this blog post for an example. But it might be worth waiting for the 0.2.0 release as it should be out in the next week.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why