Skip to content

Instantly share code, notes, and snippets.

@DmitrySikorsky
Created July 13, 2019 09:32
Show Gist options
  • Save DmitrySikorsky/33e7411bc38194e7ebad987fd37c45ce to your computer and use it in GitHub Desktop.
Save DmitrySikorsky/33e7411bc38194e7ebad987fd37c45ce to your computer and use it in GitHub Desktop.
protected TagBuilder CreateInputTag(Localization localization)
{
TagBuilder tb = new TagBuilder("input");
tb.TagRenderMode = TagRenderMode.SelfClosing;
if (!this.IsValid(localization))
tb.AddCssClass("input-validation-error");
tb.AddCssClass("field__input");
tb.AddCssClass("input");
tb.MergeAttribute("id", this.GetIdentity(localization));
tb.MergeAttribute("name", this.GetIdentity(localization));
string value = this.GetValue(localization);
if (!string.IsNullOrEmpty(value))
tb.MergeAttribute("value", value);
RequiredAttribute requiredAttribute = this.GetRequiredAttribute();
if (requiredAttribute != null)
{
tb.MergeAttribute("data-val", true.ToString().ToLower());
tb.MergeAttribute("data-val-required", string.Empty);
}
return tb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment