-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTMLHelper default css class names #17412
Comments
With Core 2.2, we were able to override the default styling of the error messages by doing the following in the Startup.cs file:
I don't remember where I took this sample code but it worked flawlessly until I upgrade my project to Core 3.0 where I get the error message:
We should be able to set the css class dynamically so we can support what ever css framework that we want. |
Thanks for contacting us. |
Why is not possible for example to remove the readonly from the css class strings? So we can use 3.1 release with the workaround. Net Core is all about cross platform and then you can't even switch CSS frameworks if you are not a rocket scientist. For me this is a fat bug :-) In my opinion not acceptable for Long Term Support Release. |
Seeing as the other thread was closed due to "not enough community involvement", allow me to add a useless comment to signify that this is a big and consistent pain point with using MVC. |
Indeed, i will like to set my own css classes for validation. |
I would really like this feature as well. I found a temporary work-around, by making a custom |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
I agree with the request, remembering to add a taghelper to every single input is quite painful. I am using Bootstrap 4 and would like to set the validation class to something else other than the current. Is there any workarround to not add an aditional tag to every single input, like create an Input tag helper that would check the model state and add the correct class? |
The workaround I linked above (https://gist.github.com/FWest98/9141b3c2f260bee0e46058897d2017d2) replaces the classes that are added, such that you can modify the exact classes you want for validation success and fail. The gist contains fixes for both the frontend jQ validation code, as well as the backend model state code. |
@FWest98 Somehow I missed your previous post with the workaround, your workarround fits like a glove, thanks |
I think I'm blocked from upgrading to .NET 5.0 because of this. There is a workaround in .NET Core 3 where you could set the I would prefer that the API didn't prevent customising the CSS class names to accommodate a web framework like Bootstrap, or just for a handmade website where you want a fine degree of control over the HTML that is output. It seems like such a necessary thing to provide in this API. Can you please (re-)consider changing these properties from I'd prefer not to litter my code with a bunch of workaround code to hack it using the DI system as suggested above (props for figuring that out and sharing, but no thanks). |
I agree. Framework have to be closed but extensible.
|
I would be happy to contribute to an implementation of this issue, but what direction should the solution take? Should it be some DI-able Config object? Any guidance from the .NET team on this? |
I'm not from the NET team, but i suggest that all other functions that get access to that static variables be changed to access an overridable function that read that static variable. So in the future anybody can override the function and change the behavior without impact.
|
Any update on that? This i realy an annoying behavior currently. It cannot be that hard to have it configurable. |
@KaiGartenschlaeger I made a first implementation for this issue (PR #34777). Let's hope this works out |
Adding API proposal as requested by @pranavkm (#34777 (comment)) Proposed APIProposed API changes: namespace Microsoft.AspNetCore.Mvc.ViewFeatures
{
public class HtmlHelperOptions
{
+ public string ValidationInputValidCssClassName { get; set; }
+ public string ValidationInputInvalidCssClassName { get; set; }
+ public string ValidationFieldValidCssClassName { get; set; }
+ public string ValidationFieldInvalidCssClassName { get; set; }
+ public string ValidationSummaryValidCssClassName { get; set; }
+ public string ValidationSummaryInvalidCssClassName { get; set; }
}
public class HtmlHelper
{
- public static readonly string ValidationInputCssClassName;
- public static readonly string ValidationInputValidCssClassName;
- public static readonly string ValidationMessageCssClassName;
- public static readonly string ValidationMessageValidCssClassName;
- public static readonly string ValidSummaryCssClassName;
- public static readonly string ValidSummaryValidCssClassName;
}
} Usage ExamplesSetting custom CSS class names, for example through DI: // In Startup::ConfigureServices
services
.AddMvc()
.AddViewOptions(options =>
{
options.HtmlHelperOptions.ValidationInputValidCssClassName = "custom";
}); This aligns with the current options already available in Alternative DesignsThere are three options regarding the old readonly strings in
RisksRemoving altogether would be a breaking change, going for any of the two other options would not have major risks to my knowledge. |
Any update? |
Unfortunately, the PR has been closed (#34777 (comment)) as this issue will be addressed in a bigger scope (#8573) |
Thank you so much for this - works great. I'm really surprised that something so obviously in need to being easily configurable/extensible requires this level of code change (which is not documented or discoverable). I'm also surprised that more people aren't complaining about this issue |
This problem is well solved in Blazor, but still not solved for this. But when using Identity in Blazor, we have to use Ragzor Page or MVC, which really sucks. Good features are separated. |
Thanks for contacting us. We're moving this issue to the |
Will anything like this ever be addressed? Both this and #8573 have now been moved another iteration - how come we are still stuck with decade-old validation technologies? |
I would still love to see this customisable in .NET. Recently came up against this issue again in a project transitioning from .NET Core 3 and had to write a |
I want to change default css class names to support bootstrap 4.
#4819
Please look on the bottom of the issue for context and explanation
I could not believe the values were hardcoded, but after 3.0 upgrade they remove the possibility to even change them.
Is there any workaround without using tag helpers ?
(Please dont tell me to use css rules for the default classes)
The text was updated successfully, but these errors were encountered: