From 718d0368f7408b7e5d6ed31b81f43494ddb03994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Sun, 9 Jul 2023 22:49:11 +0200 Subject: [PATCH] Code cleanup. --- .../TagHelpers/EditorFieldSetTagHelper.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Lombiq.HelpfulLibraries.OrchardCore/TagHelpers/EditorFieldSetTagHelper.cs b/Lombiq.HelpfulLibraries.OrchardCore/TagHelpers/EditorFieldSetTagHelper.cs index e2d78831..191a4a88 100644 --- a/Lombiq.HelpfulLibraries.OrchardCore/TagHelpers/EditorFieldSetTagHelper.cs +++ b/Lombiq.HelpfulLibraries.OrchardCore/TagHelpers/EditorFieldSetTagHelper.cs @@ -85,8 +85,8 @@ private void AppendInputAndLabel(TagHelperOutput output, bool isRequired) htmlAttributes: null); var attributes = new Dictionary(); - if (IsReadOnly) attributes["readonly"] = "readonly"; - if (isRequired) attributes["required"] = "required"; + AddBoolAttribute(attributes, IsReadOnly, "readonly"); + AddBoolAttribute(attributes, isRequired, "required"); if (InputType.EqualsOrdinalIgnoreCase("checkbox")) { @@ -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 attributes, bool value, string attributeName) + { + if (value) + { + attributes[attributeName] = attributeName; + } + } }