public static string RenderRadioButton(HtmlHelper html, BootstrapRadioButtonModel model) { if (model.tooltipConfiguration != null) model.htmlAttributes.AddRange(model.tooltipConfiguration.ToDictionary()); if (!string.IsNullOrEmpty(model.id)) 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.RadioButton(model.htmlFieldName, model.value, model.isChecked, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString() + validationMessage; }
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 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; }