dotnet / dotnet/aspnetcore

Option for adding custom css class for asp-for input tag helper

Open
#38,910 2 comments 1 reaction 0 assignees View on GitHub
api-suggestion area-mvc enhancement
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

## Background and Motivation
In asp.net core MVC and razor pages, the asp-for tag helper sets a css class for invalid input fields. But there is no way to customize that class name. Most CSS libraries have different class names for validation purposes. So it's important to give a way to change the class name and make asp.net core independent to frontend UI libraries

## Proposed API
```diff
namespace Microsoft.AspNetCore.Mvc.TagHelpers;

[HtmlTargetElement("input", Attributes = ForAttributeName, TagStructure = TagStructure.WithoutEndTag)]
public class InputTagHelper : TagHelper
{
+ [HtmlAttributeName("asp-error-class")]
+ public string ErrorClassName { get; set; }

+ // Changes to Process method to use that ErrorClassName
}
```

## Usage Examples

``` razor

```

## Alternative Designs
It would also be great to have an option to change the default error class name in the application service registration

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.