Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

TextAreaTagHelper.cs

using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace Nop.Web.Framework.TagHelpers.Public;

/// 
/// "textarea" tag helper
/// 
[HtmlTargetElement("textarea", Attributes = FOR_ATTRIBUTE_NAME)]
public partial class TextAreaTagHelper : Microsoft.AspNetCore.Mvc.TagHelpers.TextAreaTagHelper
{
    #region Constants

    protected const string FOR_ATTRIBUTE_NAME = "asp-for";
    protected const string DISABLED_ATTRIBUTE_NAME = "asp-disabled";

    #endregion

    #region Ctor

    public TextAreaTagHelper(IHtmlGenerator generator) : base(generator)
    {
    }

    #endregion

    #region Methods

    /// 
    /// Asynchronously executes the tag helper with the given context and output
    /// 
    /// Contains information associated with the current HTML tag
    /// A stateful HTML element used to generate an HTML tag
    /// A task that represents the asynchronous operation
    public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
    {
        ArgumentNullException.ThrowIfNull(context);

        ArgumentNullException.ThrowIfNull(output);

        //add disabled attribute
        if (bool.TryParse(IsDisabled, out var disabled) && disabled)
            output.Attributes.Add(new TagHelperAttribute("disabled", "disabled"));

        await base.ProcessAsync(context, output);
    }

    #endregion

    #region Properties

    /// 
    /// Indicates whether the input is disabled
    /// 
    [HtmlAttributeName(DISABLED_ATTRIBUTE_NAME)]
    public string IsDisabled { set; get; }

    #endregion
}