private TagBuilder GetInputTag() { var input1 = new TagBuilder("input") { TagRenderMode = TagRenderMode.SelfClosing }; input1.AddCssClassIf(IsValidation, "validation"); input1.Attributes.Add("id", For.Name); input1.Attributes.Add("name", For.Name); input1.Attributes.Add("value", $"{For.Model}"); input1.Attributes.AddIf(IsReadOnlyResult, "readonly"); input1.Attributes.AddIf(IsRequired, "required"); input1.Attributes.AddIf(IsBool, "type", "checkbox"); input1.AddCssClassIf(IsBool, "checkbox"); input1.Attributes.AddIf(!IsDisplay, "placeholder", For.Name.Humanize().Titleize()); // Need to account for radio and textarea input1.AddCssClassIf(!IsBool, "input"); if (IsDate && !IsReadOnlyResult) { input1.Attributes.Add("type", "date"); input1.Attributes.Add("data-show-header", false); input1.Attributes.Add("data-color", "dark"); input1.Attributes.Add("date-date-format", "YYYY-MM-DD"); input1.MergeAttribute("value", $"{For.Model:yyyy-MM-dd}"); } if (IsDateTime && !IsReadOnlyResult) { input1.Attributes.Add("type", "date"); input1.Attributes.Add("data-show-header", false); input1.Attributes.Add("data-color", "dark"); input1.Attributes.Add("date-date-format", "YYYY-MM-DD HH:mm"); input1.MergeAttribute("value", $"{For.Model:yyyy-MM-dd HH:mm}"); } if (IsRegularExpression) { input1.Attributes.Add("pattern", GetModelAttributes().GetModelAttribute <RegularExpressionAttribute>().Pattern); } if (IsCompare) { input1.Attributes.Add("data-nw-compare", GetModelAttributes().GetModelAttribute <CompareAttribute>().OtherProperty); } if (IsEditable) { input1.Attributes.AddIf(!GetModelAttributes().GetModelAttribute <EditableAttribute>().AllowEdit, "readonly"); } if (IsDisplay) { input1.Attributes.AddIf(!IsDate && !IsDateTime, "placeholder", GetModelAttributes().GetModelAttribute <DisplayAttribute>().Prompt); input1.Attributes.AddIf(IsDate, "placeholder", DateTime.Today.ToShortTimeString()); input1.Attributes.AddIf(IsDateTime, "placeholder", DateTime.Today.ToShortTimeString()); } if (IsStringLength) { var attribute = GetModelAttributes().GetModelAttribute <StringLengthAttribute>(); input1.Attributes.Add("minlength", attribute.MinimumLength); input1.Attributes.Add("maxlength", attribute.MaximumLength); } if (IsMinLength) { input1.Attributes.AddIfMissing("minlength", GetModelAttributes().GetModelAttribute <MinLengthAttribute>().Length); } if (IsMaxLength) { input1.Attributes.AddIfMissing("maxlength", GetModelAttributes().GetModelAttribute <MaxLengthAttribute>().Length); } if (IsRemote) { var attribute = GetModelAttributes().GetModelAttribute <RemoteAttribute>(); input1.Attributes.Add("data-nw-action", _urlHelper.ActionLink(attribute.Action, attribute.Controller)); input1.Attributes.AddIf(!string.IsNullOrWhiteSpace(attribute.AdditionalFields), "data-nw-additional-fields", attribute.AdditionalFields); } input1.Attributes.Add("data-nw-validation"); input1.Attributes.AddIfMissing("type", "text"); return(input1); }