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.

Custom validation class in blazor is not working as expected.

See original GitHub issue

First of all, Custom validation class attributes documentation is quite ambiguous and lack of clear instructions. It is not even stated that where to put the following code:

var editContext = new EditContext(model);
editContext.SetFieldCssClassProvider(new MyFieldClassProvider());

I have assumed that the above code has to be put inside at the beginning of HandleValidSubmit method. If I do so then it does not work on Model validation by validation attributes (data annotations) as model validation is done even before hitting the HandleValidSubmit method.

Secondly, If I am to do so then it means there is no global option to configure this. Rather I have to call the above code in every form submit which is even not working as expected?

Please confirm whether I have configured the Custom validation class attributes (as described above) correctly or it is a bug.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
TanvirArjelcommented, Feb 26, 2021

@mkArtakMSFT Surely! I shall do. We ❤️ Blazor a lot. It’s a mind-blowing framework. We want to see it as fully stable as Angular. Thanks to all you guys behind this framework.

1reaction
guardrexcommented, Feb 26, 2021

@mkArtakMSFT … The PR is up at https://github.com/dotnet/AspNetCore.Docs/pull/21634.

I put a piece in there at the end that mentions conditionally checking a subset of fields.

I’ll touch it again later when I reach the topic on my UE pass. For example, a fully working cut-'n-paste example might be best, and I might work that up later. Let’s see if what’s on the PR is good enough for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom validation class in Blazor is not working as ...
So currently setting a custom validation class of any CSS library would not work with this. I hope you understood.
Read more >
Blazor not working validations in custom component
i have a little problem with custom component in blazor server side. I try create my custom DateTime component. And when i have...
Read more >
Blazor: Validation doesn't work on a derived model
When I use a base QuoteModel object, the base class Validate() is called as expected. What am I missing? Blazor.
Read more >
Custom validator works in components but not on pages
I have a custom validator that checks for input value that conflicts with existing ones. The validator works from components but fails to ......
Read more >
ASP.NET Core Blazor | How to create custom validation attribute
Asp.net core blazor | Create custom validation attribute | custom model validation | Custom data validation Notes and Slides ...
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