public static TagBuilder GenerateTagDisplay(string id, string caption, RouteValueDictionary htmlAttributes, string tooltip = null, bool isRequired = false, string requiredSymbol = null, string requiredMessage = null, string requiredClass = null) { TagBuilder tagSpan = isRequired ? GenerateTagSpanRequired(requiredSymbol, requiredMessage, requiredClass) : null; TagBuilder tagLabel = new TagBuilder("span"); tagLabel.AddInputAttributeIsNotNullAndExpressionIsTrue("id", id, id != null); tagLabel.AddInputAttributeHtmlAttributes("class", htmlAttributes); tagLabel.AddInputAttributeHtmlAttributes("style", htmlAttributes); if (tooltip != null && !string.IsNullOrEmpty(tooltip)) { tagLabel.AddInputAttributeStaticValue("data-toggle", "tooltip"); tagLabel.AddInputAttributeStaticValue("data-placement", "top"); tagLabel.AddInputAttributeIsNotNullAndExpressionIsTrue("data-original-title", tooltip, tooltip != null); } tagLabel.InnerHtml = caption + (tagSpan != null ? tagSpan.ToMvcHtmlString(TagRenderMode.Normal).ToString() : ""); return(tagLabel); }
public static TagBuilder GenerateTagEditor(string id, string text, RouteValueDictionary htmlAttributes, string tooltip = null, bool isRequired = false, bool disabled = false) { TagBuilder tagEdit = new TagBuilder("input"); tagEdit.AddInputAttributeStaticValue("type", "text"); tagEdit.AddInputAttributeIsNotNullAndExpressionIsTrue("id", id, id != null); tagEdit.AddInputAttributeHtmlAttributes("class", htmlAttributes); tagEdit.AddInputAttributeHtmlAttributes("style", htmlAttributes); tagEdit.AddInputAttributeIfExpressionIsTrue("required", null, isRequired); tagEdit.AddInputAttributeIfExpressionIsTrue("disabled", null, disabled); if (tooltip != null && !string.IsNullOrEmpty(tooltip)) { tagEdit.AddInputAttributeStaticValue("data-toggle", "tooltip"); tagEdit.AddInputAttributeStaticValue("data-placement", "top"); tagEdit.AddInputAttributeIsNotNullAndExpressionIsTrue("data-original-title", tooltip, tooltip != null); } tagEdit.AddInputAttributeStaticValue("value", text); return(tagEdit); }
public static void MergeInputAttributeHtmlAttributes(this TagBuilder tagInput, string attributeName, RouteValueDictionary htmlAttributes) { if (htmlAttributes[attributeName] == null) { return; } RouteValueDictionary tagRouteValueDictionary = tagInput.Attributes.ToRouteValueDictionary(); htmlAttributes = HtmlHelpers.MergeHtmlAttributes(htmlAttributes, tagRouteValueDictionary); tagInput.AddInputAttributeHtmlAttributes(attributeName, htmlAttributes); }
public static void MergeInputAttributeStaticValue(this TagBuilder tagInput, string attributeName, object value) { object valueTreated = null; bool testBool; Boolean.TryParse(value.GetType().IsArray ? ((string[])value)[0] : value.ToString(), out testBool); if (testBool) { switch (attributeName.ToLowerInvariant()) { case "autofocus": case "required": case "readonly": case "disabled": case "spellcheck": valueTreated = null; break; } } else { if (value.GetType().IsArray) { valueTreated = ""; foreach (var item in (Array)value) { valueTreated += item.ToString() + " "; } } else { valueTreated = value; } } RouteValueDictionary htmlAttributes = new RouteValueDictionary(); foreach (var item in tagInput.Attributes) { htmlAttributes.Add(item.Key, item.Value); } RouteValueDictionary tagRouteValueDictionary = new RouteValueDictionary(new Dictionary <string, object>() { { attributeName.ToLowerInvariant(), valueTreated } }); htmlAttributes = HtmlHelpers.MergeHtmlAttributes(htmlAttributes, tagRouteValueDictionary); tagInput.AddInputAttributeHtmlAttributes(attributeName, htmlAttributes); }
public static TagBuilder GenerateTagProgress(string id, string caption, RouteValueDictionary htmlAttributes, double?value = null, double?maxValue = null, string tooltip = null, bool isRequired = false, bool disabled = false) { TagBuilder tagEdit = new TagBuilder("progress"); tagEdit.AddInputAttributeIsNotNullAndExpressionIsTrue("id", id, id != null); tagEdit.AddInputAttributeHtmlAttributes("class", htmlAttributes); tagEdit.AddInputAttributeHtmlAttributes("style", htmlAttributes); tagEdit.AddInputAttributeIfExpressionIsTrue("required", null, isRequired); tagEdit.AddInputAttributeIfExpressionIsTrue("disabled", null, disabled); if (tooltip != null && !string.IsNullOrEmpty(tooltip)) { tagEdit.AddInputAttributeStaticValue("data-toggle", "tooltip"); tagEdit.AddInputAttributeStaticValue("data-placement", "top"); tagEdit.AddInputAttributeIsNotNullAndExpressionIsTrue("data-original-title", tooltip, tooltip != null); } /* Injetando o Valor no Input... */ tagEdit.AddInputAttributeIsNotNullAndExpressionIsTrue("max", maxValue, maxValue != null); tagEdit.AddInputAttributeIsNotNullAndExpressionIsTrue("value", value, value != null); return(tagEdit); //return new TagBuilder_Progress<TModel, TProperty>(dynamicComponentBase).GenerateElementMvcString(TagRenderMode.Normal); }