public static string RenderControlGroupCustom(HtmlHelper html, string input, BootstrapLabelModel labelModel) { string label = Renderer.RenderLabel(html, labelModel ?? new BootstrapLabelModel { htmlFieldName = labelModel.htmlFieldName, metadata = labelModel.metadata, htmlAttributes = new { @class = "control-label" }.ToDictionary() }); bool fieldIsValid = true; if (labelModel != null && labelModel.htmlFieldName != null) fieldIsValid = html.ViewData.ModelState.IsValidField(labelModel.htmlFieldName); return new BootstrapControlGroup(input, label, ControlGroupType.textboxLike, fieldIsValid).ToHtmlString(); }
public static string RenderLabel(HtmlHelper html, BootstrapLabelModel model) { if (string.IsNullOrEmpty(model.htmlFieldName)) return null; string fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(model.htmlFieldName); if (string.IsNullOrEmpty(model.labelText)) model.labelText = model.metadata.DisplayName ?? (model.metadata.PropertyName != null ? model.metadata.PropertyName.SplitByUpperCase() : null) ?? fullHtmlFieldName.Split('.').Last().SplitByUpperCase(); TagBuilder label = new TagBuilder("label"); label.Attributes.Add("for", fullHtmlFieldName.FormatForMvcInputId() + (model.index.HasValue ? "_" + model.index.Value.ToString() : string.Empty)); label.MergeAttributes(model.htmlAttributes.FormatHtmlAttributes()); TagBuilder requiredSpan = new TagBuilder("span"); requiredSpan.AddCssClass("required"); requiredSpan.SetInnerText("*"); if ((model.showRequiredStar.HasValue && !model.showRequiredStar.Value) || (!model.showRequiredStar.HasValue && !model.metadata.IsRequired)) requiredSpan.AddCssStyle("visibility", "hidden"); if(model.innerInputType != BootstrapInputType._NotSet) { if(model.innerInputType == BootstrapInputType.CheckBox) { label.AddOrMergeCssClass("checkbox"); BootstrapCheckBoxModel inputModel = (BootstrapCheckBoxModel)model.innerInputModel; inputModel.displayValidationMessage = false; model.innerInput = MvcHtmlString.Create(inputModel.isSingleInput ? Renderer.RenderCheckBoxCustom(html, inputModel) : Renderer.RenderCheckBox(html, inputModel)); if(inputModel.htmlAttributes.Keys.Select(x => x.ToLower()).Contains("id")) label.Attributes["for"] = inputModel.htmlAttributes["id"].ToString(); } if(model.innerInputType == BootstrapInputType.Radio) { label.AddOrMergeCssClass("radio"); BootstrapRadioButtonModel inputModel = (BootstrapRadioButtonModel)model.innerInputModel; model.innerInput = MvcHtmlString.Create(Renderer.RenderRadioButton(html, inputModel)); if (inputModel.htmlAttributes.Keys.Select(x => x.ToLower()).Contains("id")) label.Attributes["for"] = inputModel.htmlAttributes["id"].ToString(); } } string innerinput = ""; if (model.innerInput != null) innerinput = model.innerInput.ToHtmlString(); label.InnerHtml = innerinput + model.labelText + requiredSpan.ToString() + model.innerValidationMessage; return label.ToString(TagRenderMode.Normal); }
public static string RenderControlGroupPassword(HtmlHelper html, BootstrapTextBoxModel inputModel, BootstrapLabelModel labelModel) { var input = Renderer.RenderTextBox(html, inputModel, true); string label = Renderer.RenderLabel(html, labelModel ?? new BootstrapLabelModel { htmlFieldName = inputModel.htmlFieldName, metadata = inputModel.metadata, htmlAttributes = new { @class = "control-label" }.ToDictionary() }); bool fieldIsValid = true; if(inputModel != null) fieldIsValid = html.ViewData.ModelState.IsValidField(inputModel.htmlFieldName); return new BootstrapControlGroup(input, label, ControlGroupType.textboxLike, fieldIsValid).ToHtmlString(); }
public static string RenderControlGroupRadioButtonTrueFalse(HtmlHelper html, BootstrapRadioButtonTrueFalseModel inputModel, BootstrapLabelModel labelModel) { if (string.IsNullOrEmpty(inputModel.htmlFieldName)) return null; var input = Renderer.RenderRadioButtonTrueFalse(html, inputModel); string label = Renderer.RenderLabel(html, labelModel ?? new BootstrapLabelModel { htmlFieldName = inputModel.htmlFieldName, metadata = inputModel.metadata, htmlAttributes = new { @class = "control-label" }.ToDictionary() }); bool fieldIsValid = true; if(inputModel != null) fieldIsValid = html.ViewData.ModelState.IsValidField(inputModel.htmlFieldName); return new BootstrapControlGroup(input, label, ControlGroupType.textboxLike, fieldIsValid).ToHtmlString(); }
public static string RenderControlGroupRadioButton(HtmlHelper html, BootstrapRadioButtonModel inputModel, BootstrapLabelModel labelModel) { 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.Radio, 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 RenderControlGroupSelectElement(HtmlHelper html, BootstrapSelectElementModel inputModel, BootstrapLabelModel labelModel, BootstrapInputType inputType) { if (string.IsNullOrEmpty(inputModel.htmlFieldName) || inputModel.selectList == null) return null; string input = string.Empty; if(inputType == BootstrapInputType.DropDownList) input = Renderer.RenderSelectElement(html, inputModel, BootstrapInputType.DropDownList); if (inputType == BootstrapInputType.ListBox) input = Renderer.RenderSelectElement(html, inputModel, BootstrapInputType.ListBox); string label = Renderer.RenderLabel(html, labelModel ?? new BootstrapLabelModel { htmlFieldName = inputModel.htmlFieldName, metadata = inputModel.metadata, htmlAttributes = new { @class = "control-label" }.ToDictionary() }); bool fieldIsValid = true; if(inputModel != null) fieldIsValid = html.ViewData.ModelState.IsValidField(inputModel.htmlFieldName); return new BootstrapControlGroup(input, label, ControlGroupType.textboxLike, fieldIsValid).ToHtmlString(); }
public static string RenderInputListItem( HtmlHelper html, BootstrapInputType inputType, string htmlFieldName, ModelMetadata metadata, int index, string inputValue, string inputText, object inputHtmlAttributes, object labelHtmlAttributes, bool inputIsChecked, bool inputIsDisabled) { string input = string.Empty; string fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(htmlFieldName); var htmlAttrs = labelHtmlAttributes.ToDictionary(); switch (inputType) { case BootstrapInputType._NotSet: break; case BootstrapInputType.CheckBoxList: { htmlAttrs.AddOrMergeCssClass("class", "checkbox").FormatHtmlAttributes(); BootstrapCheckBoxModel checkboxModel = new BootstrapCheckBoxModel { htmlFieldName = htmlFieldName, value = inputValue, metadata = metadata, htmlAttributes = inputHtmlAttributes.ToDictionary().FormatHtmlAttributes(), id = fullHtmlFieldName.FormatForMvcInputId() + "_" + index.ToString(), isChecked = inputIsChecked, isDisabled = inputIsDisabled }; input = Renderer.RenderCheckBoxCustom(html, checkboxModel); break; } case BootstrapInputType.RadioList: { htmlAttrs.AddOrMergeCssClass("class", "radio").FormatHtmlAttributes(); BootstrapRadioButtonModel radiobuttonModel = new BootstrapRadioButtonModel { htmlFieldName = htmlFieldName, value = inputValue, metadata = metadata, htmlAttributes = inputHtmlAttributes.ToDictionary().FormatHtmlAttributes(), id = fullHtmlFieldName.FormatForMvcInputId() + "_" + index.ToString(), isChecked = inputIsChecked, isDisabled = inputIsDisabled }; input = Renderer.RenderRadioButton(html, radiobuttonModel); break; } default: break; } BootstrapLabelModel labelModel = new BootstrapLabelModel { index = index, htmlFieldName = htmlFieldName, labelText = inputText, metadata = metadata, htmlAttributes = htmlAttrs, innerInput = MvcHtmlString.Create(input), showRequiredStar = false }; string labeledInput = Renderer.RenderLabel(html, labelModel); return labeledInput; }