public static string RenderFile(HtmlHelper html, BootstrapFileModel model) { string validationMessage = ""; if (model.displayValidationMessage) { string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString(); } model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata)); if (model.tooltipConfiguration != null) { model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary()); } if (model.tooltip != null) { model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary()); } var mergedHtmlAttrs = model.htmlAttributes.FormatHtmlAttributes().AddOrReplace("type", "File"); if (!string.IsNullOrEmpty(model.id)) { mergedHtmlAttrs.AddOrReplace("id", model.id); } return(html.TextBox(model.htmlFieldName, null, mergedHtmlAttrs).ToHtmlString() + validationMessage); }
public static string RenderTextArea(HtmlHelper html, BootstrapTextAreaModel model) { if (model == null || string.IsNullOrEmpty(model.htmlFieldName)) { return(null); } string validationMessage = ""; if (model.displayValidationMessage) { string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString(); } model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata)); if (!string.IsNullOrEmpty(model.id)) { model.htmlAttributes.AddOrReplace("id", model.id); } if (model.tooltipConfiguration != null) { model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary()); } return(html.TextArea(model.htmlFieldName, model.value, model.rows, model.columns, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString() + validationMessage); }
public static string RenderRadioButton(HtmlHelper html, BootstrapRadioButtonModel model) { if (model.tooltipConfiguration != null) { model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary()); } if (model.tooltip != null) { model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary()); } model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata)); if (!string.IsNullOrEmpty(model.id)) { model.htmlAttributes.AddOrReplace("id", model.id); } string validationMessage = ""; if (model.displayValidationMessage && html.ValidationMessage(model.htmlFieldName) != null) { string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString(); } return(html.RadioButton(model.htmlFieldName, model.value, model.isChecked, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString() + validationMessage); }
public static string RenderControlGroupCheckBox(HtmlHelper html, BootstrapCheckBoxModel inputModel, BootstrapLabelModel labelModel) { if (string.IsNullOrEmpty(inputModel.htmlFieldName)) { return(null); } string validationMessage = ""; if (inputModel.displayValidationMessage) { string validation = html.ValidationMessage(inputModel.htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, inputModel.validationMessageStyle).ToHtmlString(); } string label = Renderer.RenderLabel(html, labelModel ?? new BootstrapLabelModel { htmlFieldName = inputModel.htmlFieldName, metadata = inputModel.metadata, innerInputType = BootstrapInputType.CheckBox, innerInputModel = inputModel, innerValidationMessage = validationMessage }); bool fieldIsValid = true; if (inputModel != null) { fieldIsValid = html.ViewData.ModelState.IsValidField(inputModel.htmlFieldName); } return(new BootstrapControlGroup(null, label, ControlGroupType.checkboxLike, fieldIsValid).ToHtmlString()); }
public static string RenderCheckBox(HtmlHelper html, BootstrapCheckBoxModel model) { if (model.tooltipConfiguration != null) { model.htmlAttributes.AddRange(model.tooltipConfiguration.ToDictionary()); } var mergedHtmlAttrs = string.IsNullOrEmpty(model.id) ? model.htmlAttributes : model.htmlAttributes.AddOrReplace("id", model.id); string validationMessage = ""; if (model.displayValidationMessage) { string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString(); } return(html.CheckBox(model.htmlFieldName, model.isChecked, mergedHtmlAttrs.FormatHtmlAttributes()).ToHtmlString() + validationMessage); }
public static string RenderRadioButtonTrueFalse(HtmlHelper html, BootstrapRadioButtonTrueFalseModel model) { TagBuilder inputsContainer = new TagBuilder("div"); inputsContainer.AddCssClass("container-radio-true-false"); inputsContainer.AddCssStyle("display", "inline-block"); inputsContainer.AddCssStyle("margin-top", "4px"); if (model.tooltipConfiguration != null) { inputsContainer.MergeAttributes(model.tooltipConfiguration.ToDictionary()); } if (model.tooltip != null) { inputsContainer.MergeAttributes(model.tooltip.ToDictionary()); } string fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(model.htmlFieldName); bool trueValueIsSelected = false; bool falseValueIsSelected = false; if (model.metadata.Model != null) { trueValueIsSelected = model.inputTrueValue.ToString() == model.metadata.Model.ToString(); falseValueIsSelected = model.inputTrueValue.ToString() != model.metadata.Model.ToString(); } var inputTrue = Renderer.RenderLabel(html, new BootstrapLabelModel { htmlFieldName = model.htmlFieldName, labelText = model.labelTrueText, metadata = model.metadata, htmlAttributes = model.htmlAttributesLabelTrue, showRequiredStar = false, innerInputType = BootstrapInputType.Radio, innerInputModel = new BootstrapRadioButtonModel { htmlFieldName = model.htmlFieldName, value = model.inputTrueValue, metadata = model.metadata, isChecked = trueValueIsSelected, htmlAttributes = model.htmlAttributesInputTrue.AddOrReplace("id", fullHtmlFieldName.FormatForMvcInputId() + "_t") } }); var inputFalse = Renderer.RenderLabel(html, new BootstrapLabelModel { htmlFieldName = model.htmlFieldName, labelText = model.labelFalseText, metadata = model.metadata, htmlAttributes = model.htmlAttributesLabelFalse, showRequiredStar = false, innerInputType = BootstrapInputType.Radio, innerInputModel = new BootstrapRadioButtonModel { htmlFieldName = model.htmlFieldName, value = model.inputFalseValue, metadata = model.metadata, isChecked = falseValueIsSelected, htmlAttributes = model.htmlAttributesInputFalse.AddOrReplace("id", fullHtmlFieldName.FormatForMvcInputId() + "_f") } }); string helpText = model.helpText != null?model.helpText.ToHtmlString() : string.Empty; string validationMessage = ""; if (model.displayValidationMessage) { string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString(); } inputsContainer.InnerHtml = inputTrue + inputFalse; return(inputsContainer.ToString() + helpText + validationMessage); }
public static string RenderFormGroupCheckBox(HtmlHelper html, BootstrapCheckBoxModel inputModel, BootstrapLabelModel labelModel) { var input = Renderer.RenderCheckBoxCustom(html, inputModel); string validationMessage = ""; if (inputModel.displayValidationMessage) { string validation = html.ValidationMessage(inputModel.htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, inputModel.validationMessageStyle).ToHtmlString(); } var widthlg = ""; if (inputModel.LabelWidthLg != 0) { var width = inputModel.LabelWidthLg.ToString(); widthlg = " col-lg-" + width; } var widthMd = ""; if (inputModel.LabelWidthMd != 0) { var width = inputModel.LabelWidthMd.ToString(); widthMd = " col-md-" + width; } var widthSm = ""; if (inputModel.LabelWidthSm != 0) { var width = inputModel.LabelWidthSm.ToString(); widthSm = " col-sm-" + width; } var widthXs = ""; if (inputModel.LabelWidthXs != 0) { var width = inputModel.LabelWidthXs.ToString(); widthXs = " col-xs-" + width; } var offsetlg = ""; if (inputModel.LabelOffsetLg != 0) { var offset = inputModel.LabelOffsetLg.ToString(); offsetlg = " col-lg-offset-" + offset; } var offsetMd = ""; if (inputModel.LabelOffsetMd != 0) { var offset = inputModel.LabelOffsetMd.ToString(); offsetMd = " col-md-offset-" + offset; } var offsetSm = ""; if (inputModel.LabelOffsetSm != 0) { var offset = inputModel.LabelOffsetSm.ToString(); offsetSm = " col-sm-offset-" + offset; } var offsetXs = ""; if (inputModel.LabelOffsetXs != 0) { var offset = inputModel.LabelOffsetXs.ToString(); offsetXs = " col-xs-offset-" + offset; } string label = Renderer.RenderLabel(html, labelModel ?? new BootstrapLabelModel { htmlFieldName = inputModel.htmlFieldName, metadata = inputModel.metadata, innerInputType = BootstrapInputType.CheckBox, innerInputModel = inputModel, innerValidationMessage = validationMessage, htmlAttributes = new { @class = widthlg + widthMd + widthSm + widthXs + offsetlg + offsetMd + offsetSm + offsetXs }.ToDictionary() }); bool fieldIsValid = true; if (inputModel != null) { fieldIsValid = html.ViewData.ModelState.IsValidField(inputModel.htmlFieldName); } return(new BootstrapFormGroup(input, null, FormGroupType.textboxLike, fieldIsValid).ToHtmlString()); }
public static string RenderSelectElement(HtmlHelper html, BootstrapSelectElementModel model, BootstrapInputType inputType) { if (model.selectList == null) { throw new Exception("The SelectList is null."); } string combinedHtml = "{0}{1}{2}"; if (model.selectedValue != null) { foreach (var item in model.selectList) { if (item.Value == model.selectedValue.ToString()) { item.Selected = true; } } } model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata)); if (model.tooltipConfiguration != null) { model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary()); } if (model.tooltip != null) { model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary()); } if (!string.IsNullOrEmpty(model.id)) { model.htmlAttributes.AddOrReplace("id", model.id); } // assign size class model.htmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForInputSize(model.size)); // build html for input string input = string.Empty; if (inputType == BootstrapInputType.DropDownList) { input = html.DropDownList(model.htmlFieldName, model.selectList, model.optionLabel, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString(); } if (inputType == BootstrapInputType.ListBox) { input = html.ListBox(model.htmlFieldName, model.selectList, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString(); } // account for appendString, prependString, and AppendButtons TagBuilder appendPrependContainer = new TagBuilder("div"); if (!string.IsNullOrEmpty(model.prependString) | !string.IsNullOrEmpty(model.appendString) | model.appendButtons.Count() > 0) { string addOnPrependString = ""; string addOnAppendString = ""; string addOnPrependButtons = ""; string addOnAppendButtons = ""; TagBuilder addOn = new TagBuilder("span"); addOn.AddCssClass("add-on"); if (!string.IsNullOrEmpty(model.prependString)) { appendPrependContainer.AddOrMergeCssClass("input-prepend"); addOn.InnerHtml = model.prependString; addOnPrependString = addOn.ToString(); } if (!string.IsNullOrEmpty(model.appendString)) { appendPrependContainer.AddOrMergeCssClass("input-append"); addOn.InnerHtml = model.appendString; addOnAppendString = addOn.ToString(); } if (model.appendButtons.Count() > 0) { appendPrependContainer.AddOrMergeCssClass("input-append"); ((List <BootstrapButton>)model.appendButtons).ForEach(x => addOnAppendButtons += x.ToHtmlString()); } if (model.prependButtons.Count() > 0) { appendPrependContainer.AddOrMergeCssClass("input-append"); ((List <BootstrapButton>)model.prependButtons).ForEach(x => addOnPrependButtons += x.ToHtmlString()); } appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependString + "{0}" + addOnAppendString + addOnAppendButtons; combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}"; } string helpText = model.helpText != null?model.helpText.ToHtmlString() : string.Empty; string validationMessage = ""; if (model.displayValidationMessage) { string validation = html.ValidationMessage((string)model.htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString(); } return(MvcHtmlString.Create(string.Format(combinedHtml, input, helpText, validationMessage)).ToString()); }
public static string RenderTextBox(HtmlHelper html, BootstrapTextBoxModel model, bool isPassword) { if (model == null || string.IsNullOrEmpty(model.htmlFieldName)) { return(null); } string combinedHtml = "{0}{1}{2}"; model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata)); if (!string.IsNullOrEmpty(model.id)) { model.htmlAttributes.Add("id", model.id); } if (model.tooltipConfiguration != null) { model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary()); } // assign placeholder class if (!string.IsNullOrEmpty(model.placeholder)) { model.htmlAttributes.Add("placeholder", model.placeholder); } // assign size class model.htmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForInputSize(model.size)); // build html for input var input = isPassword ? html.Password(model.htmlFieldName, null, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString() : html.TextBox(model.htmlFieldName, model.value, model.format, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString(); // account for appendString, prependString, and AppendButtons if (!string.IsNullOrEmpty(model.prependString) || !string.IsNullOrEmpty(model.appendString) || model.prependButtons.Any() || model.appendButtons.Any() || model.iconPrepend != Icons._not_set || model.iconAppend != Icons._not_set || !string.IsNullOrEmpty(model.iconPrependCustomClass) || !string.IsNullOrEmpty(model.iconAppendCustomClass)) { TagBuilder appendPrependContainer = new TagBuilder("div"); string addOnPrependString = ""; string addOnAppendString = ""; string addOnPrependButtons = ""; string addOnAppendButtons = ""; string addOnPrependIcon = ""; string addOnAppendIcon = ""; TagBuilder addOn = new TagBuilder("span"); addOn.AddCssClass("add-on"); if (!string.IsNullOrEmpty(model.prependString)) { appendPrependContainer.AddOrMergeCssClass("input-prepend"); addOn.InnerHtml = model.prependString; addOnPrependString = addOn.ToString(); } if (!string.IsNullOrEmpty(model.appendString)) { appendPrependContainer.AddOrMergeCssClass("input-append"); addOn.InnerHtml = model.appendString; addOnAppendString = addOn.ToString(); } if (model.prependButtons.Count() > 0) { appendPrependContainer.AddOrMergeCssClass("input-prepend"); model.prependButtons.ForEach(x => addOnPrependButtons += x.ToHtmlString()); } if (model.appendButtons.Count() > 0) { appendPrependContainer.AddOrMergeCssClass("input-append"); model.appendButtons.ForEach(x => addOnAppendButtons += x.ToHtmlString()); } if (model.iconPrepend != Icons._not_set) { appendPrependContainer.AddOrMergeCssClass("input-prepend"); addOn.InnerHtml = new BootstrapIcon(model.iconPrepend, model.iconPrependIsWhite).ToHtmlString(); addOnPrependIcon = addOn.ToString(); } if (model.iconAppend != Icons._not_set) { appendPrependContainer.AddOrMergeCssClass("input-append"); addOn.InnerHtml = new BootstrapIcon(model.iconAppend, model.iconAppendIsWhite).ToHtmlString(); addOnAppendIcon = addOn.ToString(); } if (!string.IsNullOrEmpty(model.iconPrependCustomClass)) { appendPrependContainer.AddOrMergeCssClass("input-prepend"); var i = new TagBuilder("i"); i.AddCssClass(model.iconPrependCustomClass); addOn.InnerHtml = i.ToString(TagRenderMode.Normal); addOnPrependIcon = addOn.ToString(); } if (!string.IsNullOrEmpty(model.iconAppendCustomClass)) { appendPrependContainer.AddOrMergeCssClass("input-append"); var i = new TagBuilder("i"); i.AddCssClass(model.iconAppendCustomClass); addOn.InnerHtml = i.ToString(TagRenderMode.Normal); addOnAppendIcon = addOn.ToString(); } appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependIcon + addOnPrependString + "{0}" + addOnAppendString + addOnAppendIcon + addOnAppendButtons; combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}"; } string helpText = model.helpText != null?model.helpText.ToHtmlString() : string.Empty; string validationMessage = ""; if (model.displayValidationMessage) { string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString(); } return(MvcHtmlString.Create(string.Format(combinedHtml, input, validationMessage, helpText)).ToString()); }
public static string RenderTextBox(HtmlHelper html, BootstrapTextBoxModel model, bool isPassword) { var combinedHtml = "{0}{1}{2}"; model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata)); model.htmlAttributes.AddOrMergeCssClass("class", "form-control"); if (!string.IsNullOrEmpty(model.id)) { model.htmlAttributes.Add("id", model.id); } if (model.tooltipConfiguration != null) { model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary()); } if (model.tooltip != null) { model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary()); } if (model.typehead != null) { model.htmlAttributes.MergeHtmlAttributes(model.typehead.ToDictionary(html)); } // assign placeholder class if (!string.IsNullOrEmpty(model.placeholder)) { model.htmlAttributes.Add("placeholder", model.placeholder); } // assign size class model.htmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForInputSize(model.size)); if (model.disabled) { model.htmlAttributes.Add("disabled", "disabled"); } var widthlg = ""; if (model.InputWidthLg != 0) { var width = model.InputWidthLg.ToString(); widthlg = " col-lg-" + width; } var widthMd = ""; if (model.InputWidthMd != 0) { var width = model.InputWidthMd.ToString(); widthMd = " col-md-" + width; } var widthSm = ""; if (model.InputWidthSm != 0) { var width = model.InputWidthSm.ToString(); widthSm = " col-sm-" + width; } var widthXs = ""; if (model.InputWidthXs != 0) { var width = model.InputWidthXs.ToString(); widthXs = " col-xs-" + width; } var offsetlg = ""; if (model.InputOffsetLg != 0) { var offset = model.InputOffsetLg.ToString(); offsetlg = " col-lg-offset-" + offset; } var offsetMd = ""; if (model.InputOffsetMd != 0) { var offset = model.InputOffsetMd.ToString(); offsetMd = " col-md-offset-" + offset; } var offsetSm = ""; if (model.InputOffsetSm != 0) { var offset = model.InputOffsetSm.ToString(); offsetSm = " col-sm-offset-" + offset; } var offsetXs = ""; if (model.InputOffsetXs != 0) { var offset = model.InputOffsetXs.ToString(); offsetXs = " col-xs-offset-" + offset; } var widthoffset = widthlg + widthMd + widthSm + widthXs + offsetlg + offsetMd + offsetSm + offsetXs; // account for appendString, prependString, and AppendButtons if (!string.IsNullOrEmpty(model.prependString) || !string.IsNullOrEmpty(model.appendString) || model.prependButtons.Any() || model.appendButtons.Any() || !string.IsNullOrEmpty(model.iconPrepend) || !string.IsNullOrEmpty(model.iconAppend) || !string.IsNullOrEmpty(model.iconPrependCustomClass) || !string.IsNullOrEmpty(model.iconAppendCustomClass) || !string.IsNullOrEmpty(widthoffset)) { var appendPrependContainer = new TagBuilder("div"); var addOnPrependString = ""; var addOnAppendString = ""; var addOnPrependButtons = ""; var addOnAppendButtons = ""; var addOnPrependIcon = ""; var addOnAppendIcon = ""; var addOn = new TagBuilder("span"); addOn.AddCssClass("input-group-addon"); if (!string.IsNullOrEmpty(model.prependString)) { appendPrependContainer.AddOrMergeCssClass("input-group"); addOn.InnerHtml = model.prependString; addOnPrependString = addOn.ToString(); } if (!string.IsNullOrEmpty(model.appendString)) { appendPrependContainer.AddOrMergeCssClass("input-group"); addOn.InnerHtml = model.appendString; addOnAppendString = addOn.ToString(); } if (model.prependButtons.Count > 0) { appendPrependContainer.AddOrMergeCssClass("input-group"); var span = new TagBuilder("span"); span.AddOrMergeCssClass("input-group-btn"); model.prependButtons.ForEach(x => addOnPrependButtons += x.ToHtmlString()); span.InnerHtml = addOnPrependButtons; addOnPrependButtons = span.ToString(); } if (model.appendButtons.Count > 0) { appendPrependContainer.AddOrMergeCssClass("input-group"); var span = new TagBuilder("span"); span.AddOrMergeCssClass("input-group-btn"); model.appendButtons.ForEach(x => addOnAppendButtons += x.ToHtmlString()); span.InnerHtml = addOnAppendButtons; addOnAppendButtons = span.ToString(); } if (!string.IsNullOrEmpty(model.iconPrepend)) { appendPrependContainer.AddOrMergeCssClass("input-icon icon-left"); addOnPrependIcon = new BootstrapIcon(model.iconPrepend, model.iconPrependIsWhite).HtmlAttributes(new { @class = model.prependIconStyle }).ToHtmlString(); } if (!string.IsNullOrEmpty(model.iconAppend)) { appendPrependContainer.AddOrMergeCssClass("input-icon icon-right"); addOnAppendIcon = new BootstrapIcon(model.iconAppend, model.iconAppendIsWhite).HtmlAttributes(new { @class = model.appendIconStyle }).ToHtmlString(); } if (!string.IsNullOrEmpty(model.iconPrependCustomClass)) { appendPrependContainer.AddOrMergeCssClass("input-prepend"); var i = new TagBuilder("i"); i.AddCssClass(model.iconPrependCustomClass); addOn.InnerHtml = i.ToString(TagRenderMode.Normal); addOnPrependIcon = addOn.ToString(); } if (!string.IsNullOrEmpty(model.iconAppendCustomClass)) { appendPrependContainer.AddOrMergeCssClass("input-append"); var i = new TagBuilder("i"); i.AddCssClass(model.iconAppendCustomClass); addOn.InnerHtml = i.ToString(TagRenderMode.Normal); addOnAppendIcon = addOn.ToString(); } appendPrependContainer.AddOrMergeCssClass(widthlg + widthMd + widthSm + widthXs); appendPrependContainer.AddOrMergeCssClass(offsetlg + offsetMd + offsetSm + offsetXs); switch (model.size) { case InputSize.XSmall: appendPrependContainer.AddOrMergeCssClass("input-group-xs"); break; case InputSize.Small: appendPrependContainer.AddOrMergeCssClass("input-group-sm"); break; case InputSize.Large: appendPrependContainer.AddOrMergeCssClass("input-group-lg"); break; case InputSize.XLarge: appendPrependContainer.AddOrMergeCssClass("input-group-xl"); break; } appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependString + "{0}" + addOnPrependIcon + addOnAppendString + addOnAppendIcon + addOnAppendButtons + "{1}"; combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{2}"; } // build html for input var input = isPassword ? html.Password(model.htmlFieldName, null, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString() : html.TextBox(model.htmlFieldName, model.value, model.format, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString(); var helpText = model.helpText != null?model.helpText.ToHtmlString() : string.Empty; var validationMessage = ""; if (model.displayValidationMessage) { var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString(); } return(MvcHtmlString.Create(string.Format(combinedHtml, input, helpText, validationMessage)).ToString()); }
public static string RenderInputListContainer( HtmlHelper html, string htmlFieldName, List <string> inputs, int?numberOfColumns, bool displayInColumnsCondition, int columnPixelWidth, bool displayInlineBlock, int marginRightPx, bool displayValidationMessage, HelpTextStyle validationMessageStyle ) { TagBuilder container = new TagBuilder("div"); container.AddCssClass("input-list-container"); if (displayValidationMessage) { container.AddCssStyle("display", "inline-block"); container.AddCssStyle("vertical-align", "middle"); container.AddCssStyle("margin-top", "4px"); } if (numberOfColumns.HasValue && displayInColumnsCondition) { container.AddCssStyle("max-width", (columnPixelWidth * numberOfColumns).ToString() + "px"); List <string> columnedInputs = new List <string>(); TagBuilder columnDiv = new TagBuilder("div"); columnDiv.AddCssClass("input-list-column"); columnDiv.AddCssStyle("width", columnPixelWidth.ToString() + "px"); columnDiv.AddCssStyle("display", "inline-block"); foreach (var input in inputs) { columnDiv.InnerHtml = input; columnedInputs.Add(columnDiv.ToString()); } inputs = columnedInputs; } if (displayInlineBlock) { List <string> columnedInputs = new List <string>(); TagBuilder columnDiv = new TagBuilder("div"); columnDiv.AddCssClass("input-list-inline"); columnDiv.AddCssStyle("display", "inline-block"); columnDiv.AddCssStyle("margin-right", marginRightPx.ToString() + "px"); foreach (var input in inputs) { columnDiv.InnerHtml = input; columnedInputs.Add(columnDiv.ToString()); } inputs = columnedInputs; } string inputsCombined = string.Empty; inputs.ForEach(c => inputsCombined += c); container.InnerHtml = inputsCombined; string validationMessage = ""; if (displayValidationMessage) { string validation = html.ValidationMessage(htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, validationMessageStyle).ToHtmlString(); } return(container.ToString(TagRenderMode.Normal) + validationMessage); }
public static string RenderReadOnly(HtmlHelper html, BootstrapReadOnlyModel model, bool isPassword) { var combinedHtml = "{0}{1}{2}"; model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata)); if (!string.IsNullOrEmpty(model.id)) { model.htmlAttributes.Add("id", model.id); } if (model.tooltipConfiguration != null) { model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary()); } if (model.tooltip != null) { model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary()); } // assign placeholder class if (!string.IsNullOrEmpty(model.placeholder)) { model.htmlAttributes.Add("placeholder", model.placeholder); } // build html for input string input = html.Hidden(model.htmlFieldName, model.value).ToHtmlString(); if (model.value != null && model.value.GetType().IsEnum) { input = input + ((Enum)model.value).GetEnumDescription(); } else { input = input + html.Encode(model.value); } // account for appendString, prependString, and AppendButtons if (!string.IsNullOrEmpty(model.prependString) || !string.IsNullOrEmpty(model.appendString) || model.prependButtons.Any() || model.appendButtons.Any() || model.iconPrepend != Icons._not_set || model.iconAppend != Icons._not_set || !string.IsNullOrEmpty(model.iconPrependCustomClass) || !string.IsNullOrEmpty(model.iconAppendCustomClass)) { var appendPrependContainer = new TagBuilder("div"); var addOnPrependString = ""; var addOnAppendString = ""; var addOnPrependButtons = ""; var addOnAppendButtons = ""; var addOnPrependIcon = ""; var addOnAppendIcon = ""; var addOn = new TagBuilder("span"); addOn.AddCssClass("add-on"); if (!string.IsNullOrEmpty(model.prependString)) { appendPrependContainer.AddOrMergeCssClass("input-prepend"); addOn.InnerHtml = model.prependString; addOnPrependString = addOn.ToString(); } if (!string.IsNullOrEmpty(model.appendString)) { appendPrependContainer.AddOrMergeCssClass("input-append"); addOn.InnerHtml = model.appendString; addOnAppendString = addOn.ToString(); } if (model.prependButtons.Count > 0) { appendPrependContainer.AddOrMergeCssClass("input-prepend"); model.prependButtons.ForEach(x => addOnPrependButtons += x.ToHtmlString()); } if (model.appendButtons.Count > 0) { appendPrependContainer.AddOrMergeCssClass("input-append"); model.appendButtons.ForEach(x => addOnAppendButtons += x.ToHtmlString()); } if (model.iconPrepend != Icons._not_set) { appendPrependContainer.AddOrMergeCssClass("input-prepend"); addOn.InnerHtml = new BootstrapIcon(model.iconPrepend, model.iconPrependIsWhite).ToHtmlString(); addOnPrependIcon = addOn.ToString(); } if (model.iconAppend != Icons._not_set) { appendPrependContainer.AddOrMergeCssClass("input-append"); addOn.InnerHtml = new BootstrapIcon(model.iconAppend, model.iconAppendIsWhite).ToHtmlString(); addOnAppendIcon = addOn.ToString(); } if (!string.IsNullOrEmpty(model.iconPrependCustomClass)) { appendPrependContainer.AddOrMergeCssClass("input-prepend"); var i = new TagBuilder("i"); i.AddCssClass(model.iconPrependCustomClass); addOn.InnerHtml = i.ToString(TagRenderMode.Normal); addOnPrependIcon = addOn.ToString(); } if (!string.IsNullOrEmpty(model.iconAppendCustomClass)) { appendPrependContainer.AddOrMergeCssClass("input-append"); var i = new TagBuilder("i"); i.AddCssClass(model.iconAppendCustomClass); addOn.InnerHtml = i.ToString(TagRenderMode.Normal); addOnAppendIcon = addOn.ToString(); } appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependIcon + addOnPrependString + "{0}" + addOnAppendString + addOnAppendIcon + addOnAppendButtons; combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}"; } var helpText = model.helpText != null?model.helpText.ToHtmlString() : string.Empty; var validationMessage = ""; if (model.displayValidationMessage && html.ValidationMessage(model.htmlFieldName) != null) { var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString(); } return(MvcHtmlString.Create(string.Format(combinedHtml, input, helpText, validationMessage)).ToString()); }