Skip to content

Commit b81e355

Browse files
nopSolutions#5152 Added an opportunity to using custom attributes in nop-textarea tag helper
1 parent c756e02 commit b81e355

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/Presentation/Nop.Web.Framework/TagHelpers/Admin/NopTextAreaTagHelper.cs

+14-8
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ public class NopTextAreaTagHelper : TextAreaTagHelper
1616

1717
private const string FOR_ATTRIBUTE_NAME = "asp-for";
1818
private const string REQUIRED_ATTRIBUTE_NAME = "asp-required";
19-
private const string DISABLED_ATTRIBUTE_NAME = "asp-disabled";
19+
private const string CUSTOM_HTML_ATTRIBUTES = "html-attributes";
2020

2121
#endregion
2222

2323
#region Properties
2424

2525
/// <summary>
26-
/// Indicates whether the input is disabled
26+
/// Custom html attributes
2727
/// </summary>
28-
[HtmlAttributeName(DISABLED_ATTRIBUTE_NAME)]
29-
public string IsDisabled { set; get; }
28+
[HtmlAttributeName(CUSTOM_HTML_ATTRIBUTES)]
29+
public object CustomHtmlAttributes { set; get; }
3030

3131
/// <summary>
3232
/// Indicates whether the field is required
@@ -70,10 +70,16 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
7070
: "form-control";
7171
output.Attributes.SetAttribute("class", classValue);
7272

73-
//add disabled attribute
74-
if (bool.TryParse(IsDisabled, out var disabled) && disabled)
75-
output.Attributes.Add(new TagHelperAttribute("disabled", "disabled"));
76-
73+
//set custom html attributes
74+
var htmlAttributesDictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(CustomHtmlAttributes);
75+
if (htmlAttributesDictionary?.Count > 0)
76+
{
77+
foreach (var (key, value) in htmlAttributesDictionary)
78+
{
79+
output.Attributes.Add(key, value);
80+
}
81+
}
82+
7783
//additional parameters
7884
var rowsNumber = output.Attributes.ContainsName("rows") ? output.Attributes["rows"].Value : 4;
7985
output.Attributes.SetAttribute("rows", rowsNumber);

0 commit comments

Comments
 (0)