Skip to content

Commit

Permalink
Admin input tag helper - fix attribute "disabled"
Browse files Browse the repository at this point in the history
  • Loading branch information
support committed Sep 21, 2023
1 parent 00d36d9 commit 0056db0
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/Web/Grand.Web.Common/TagHelpers/Admin/AdminInputTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,6 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
//clear the output
output.SuppressOutput();

//disabled attribute
bool.TryParse(IsDisabled, out var disabled);
if (disabled)
{
var d = new TagHelperAttribute("disabled", "disabled");
output.Attributes.Add(d);
}

//required asterisk
bool.TryParse(IsRequired, out var required);
if (required)
Expand All @@ -126,21 +118,25 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
object htmlAttributes = null;
if (string.IsNullOrEmpty(RenderFormControlClass) && For.Metadata.ModelType.Name.Equals("String") || renderFormControlClass)
htmlAttributes = new { @class = "form-control k-input" };


//disabled attribute
bool.TryParse(IsDisabled, out var disabled);
if (disabled)
{
if(htmlAttributes == null)
htmlAttributes = new { @disabled = "disabled" };
else
{
htmlAttributes = new { @class = "form-control k-input", @disabled = "disabled" };
}
}
var viewEngine = GetPrivateFieldValue(_htmlHelper, "_viewEngine") as IViewEngine;
var bufferScope = GetPrivateFieldValue(_htmlHelper, "_bufferScope") as IViewBufferScope;
if (SelectItems != null)
{
if (SelectItems.Any())
{
if (_htmlHelper.ViewData.ContainsKey("SelectList"))
{
_htmlHelper.ViewData["SelectList"] = SelectItems;
}
else
{
_htmlHelper.ViewData.Add("SelectList", SelectItems);
}
_htmlHelper.ViewData["SelectList"] = SelectItems;
}
else
{
Expand All @@ -152,9 +148,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
{
_htmlHelper.ViewData.Add("SelectList", new List<SelectListItem>());
}

}

}

var templateBuilder = new TemplateBuilder(
Expand All @@ -167,7 +161,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
Template,
readOnly: false,
additionalViewData: new { htmlAttributes, postfix = this.Postfix });

var htmlOutput = await templateBuilder.Build();
output.Content.SetHtmlContent(htmlOutput.RenderHtmlContent());
}
Expand Down

0 comments on commit 0056db0

Please sign in to comment.