public override void WriteTo(TextWriter writer, HtmlEncoder encoder) { Func <IncControlBase <TModel>, bool> isForDefClass = @base => [email protected](HtmlAttribute.Class).With(r => r.Contains("col-")); bool isV3orMore = IncodingHtmlHelper.BootstrapVersion == BootstrapOfVersion.v3; bool isStatic = Input.GetType().Name.Contains("IncStaticControl"); AddClass(isV3orMore ? B.Form_group.ToLocalization() : "control-group"); if (IncodingHtmlHelper.FormGroupClass != null) { AddClass(IncodingHtmlHelper.FormGroupClass); } Label.AddClass(B.Control_label); if (isV3orMore && isForDefClass(Label)) { Label.AddClass(IncodingHtmlHelper.Def_Label_CustomClass ?? IncodingHtmlHelper.Def_Label_Class.ToLocalization()); } if (!isV3orMore) { Control.AddClass("controls"); } if (string.IsNullOrWhiteSpace(Control.GetAttr(HtmlAttribute.Class))) { Control.AddClass(isV3orMore ? (IncodingHtmlHelper.Def_Control_CustomClass ?? IncodingHtmlHelper.Def_Control_Class.ToLocalization()) : isStatic ? string.Empty : "control-group"); } if (isV3orMore && !typeof(TInput).Name.Contains("IncCheckBoxControl")) { Input.AddClass(isStatic ? B.Form_static_control.ToLocalization() : B.Form_control.ToLocalization()); } var nestedValidationWithControl = NestedValidationWithControl ?? IncodingHtmlHelper.IsNestedValidationWithControl ?? false; Control.BuildContent = builder => { builder.AppendHtml(Input); if (nestedValidationWithControl) { builder.AppendHtml(Validation); } }; TagBuilder div = new TagBuilder(HtmlTag.Div.ToStringLower()); div.MergeAttributes(GetAttributes(), true); div.InnerHtml.AppendHtml(Label); div.InnerHtml.AppendHtml(Control); if (!nestedValidationWithControl) { div.InnerHtml.AppendHtml(Validation); } div.InnerHtml.AppendHtml(HelpBlock); div.WriteTo(writer, encoder); }
public IncHorizontalControl(IncLabelControl label, TInput input, IncControlBase validation) { Label = label; Label.AddClass(IncodingHtmlHelper.BootstrapVersion == BootstrapOfVersion.v3 ? "control-label col-md-3" : "control-label"); Input = input; if (IncodingHtmlHelper.BootstrapVersion == BootstrapOfVersion.v3) { Input.AddClass("form-control"); } Validation = validation; HelpBlock = new IncHelpBlockControl(); AddClass(IncodingHtmlHelper.BootstrapVersion == BootstrapOfVersion.v3 ? "form-group col-md-12" : "control-group"); }
public override MvcHtmlString ToHtmlString() { Func <IncControlBase, bool> isForDefClass = @base => [email protected](HtmlAttribute.Class).With(r => r.Contains("col-")); bool isV3orMore = IncodingHtmlHelper.BootstrapVersion == BootstrapOfVersion.v3; bool isStatic = Input.GetType().Name.Contains("IncStaticControl"); AddClass(isV3orMore ? B.Form_group.ToLocalization() : "control-group"); Label.AddClass(B.Control_label); if (isV3orMore && isForDefClass(Label)) { Label.AddClass(IncodingHtmlHelper.Def_Label_Class.ToLocalization()); } if (!isV3orMore) { Control.AddClass("controls"); } if (string.IsNullOrWhiteSpace(Control.GetAttr(HtmlAttribute.Class))) { Control.AddClass(isV3orMore ? IncodingHtmlHelper.Def_Control_Class.ToLocalization() : isStatic ? string.Empty : "control-group"); } var stringBuilder = new StringBuilder(); stringBuilder.Append(Label.ToHtmlString()); if (isV3orMore && !typeof(TInput).Name.Contains("IncCheckBoxControl")) { Input.AddClass(isStatic ? B.Form_static_control.ToLocalization() : B.Form_control.ToLocalization()); } Control.Content = Input.ToHtmlString(); stringBuilder.Append(Control.ToHtmlString()); stringBuilder.Append(Validation.ToHtmlString()); stringBuilder.Append(HelpBlock.ToHtmlString()); var controlGroup = IncodingHtmlHelper.CreateTag(HtmlTag.Div, new MvcHtmlString(stringBuilder.ToString()), GetAttributes()); return(new MvcHtmlString(controlGroup.ToString())); }