Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig committed Jul 9, 2023
1 parent 4c88d4f commit 718d036
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ private void AppendInputAndLabel(TagHelperOutput output, bool isRequired)
htmlAttributes: null);

var attributes = new Dictionary<string, object>();
if (IsReadOnly) attributes["readonly"] = "readonly";
if (isRequired) attributes["required"] = "required";
AddBoolAttribute(attributes, IsReadOnly, "readonly");
AddBoolAttribute(attributes, isRequired, "required");

if (InputType.EqualsOrdinalIgnoreCase("checkbox"))
{
Expand Down Expand Up @@ -168,5 +168,11 @@ private static bool HasRequiredAttribute(ModelExpression modelExpression) =>
.GetCustomAttributes(typeof(RequiredAttribute), inherit: false)
.FirstOrDefault() is RequiredAttribute;

private static void MakeRequired(TagBuilder tagBuilder) => tagBuilder.Attributes.Add("required", "required");
private static void AddBoolAttribute(IDictionary<string, object> attributes, bool value, string attributeName)
{
if (value)
{
attributes[attributeName] = attributeName;
}
}
}

0 comments on commit 718d036

Please sign in to comment.