public BootstrapInputListFromEnum(HtmlHelper html, string htmlFieldName, ModelMetadata metadata, BootstrapInputType inputType) { this.html = html; this._model.htmlFieldName = htmlFieldName; this._model.metadata = metadata; this._model.inputType = inputType; }
public BootstrapControlGroupInputList( HtmlHelper html, string htmlFieldName, ModelMetadata metadata, Expression <Func <TModel, IEnumerable <TSource> > > sourceDataExpression, Expression <Func <TSource, SValue> > valueExpression, Expression <Func <TSource, SText> > textExpression, BootstrapInputType inputType) : base(html, htmlFieldName, metadata, sourceDataExpression, valueExpression, textExpression, inputType) { this._model.displayValidationMessage = true; }
public BootstrapInputList( HtmlHelper html, string htmlFieldName, ModelMetadata metadata, Expression <Func <TModel, IEnumerable <TSource> > > sourceDataExpression, Expression <Func <TSource, SValue> > valueExpression, Expression <Func <TSource, SText> > textExpression, BootstrapInputType inputType) { this.html = html; this._model.htmlFieldName = htmlFieldName; this._model.metadata = metadata; this._model.sourceDataExpression = sourceDataExpression; this._model.valueExpression = valueExpression; this._model.textExpression = textExpression; this._model.inputType = inputType; }
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 BootstrapControlGroupInputListFromEnum(HtmlHelper html, string htmlFieldName, ModelMetadata metadata, BootstrapInputType inputType) : base(html, htmlFieldName, metadata, inputType) { this._model.displayValidationMessage = true; }
public BootstrapFormGroupInputListLabeled(HtmlHelper html, object inputModel, BootstrapInputType inputType) : base(html, inputModel, inputType) { this._labelModel.htmlAttributes = _labelModel.htmlAttributes.AddOrMergeCssClass("class", "control-label"); }
public BootstrapInputLabeled(HtmlHelper html, dynamic inputModel, BootstrapInputType inputType) : base(html, (string)inputModel.htmlFieldName, (ModelMetadata)inputModel.metadata) { this._inputModel = inputModel; this._inputType = inputType; }
public static string RenderSelectElement(HtmlHelper html, BootstrapSelectElementModel model, BootstrapInputType inputType) { 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 && html.ValidationMessage(model.htmlFieldName) != null ) { 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 RenderControlGroupSelectElement(HtmlHelper html, BootstrapSelectElementModel inputModel, BootstrapLabelModel labelModel, BootstrapInputType inputType) { 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); }
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 BootstrapControlGroupLabeled(HtmlHelper html, object inputModel, BootstrapInputType inputType) : base(html, inputModel, inputType) { }
public BootstrapControlGroupLabeled(HtmlHelper html, object inputModel, BootstrapInputType inputType) : base(html, inputModel, inputType) { }
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; }
public BootstrapInputListFromEnum(HtmlHelper html, string htmlFieldName, ModelMetadata metadata, BootstrapInputType inputType) { this.html = html; this._model.htmlFieldName = htmlFieldName; this._model.metadata = metadata; this._model.inputType = inputType; }
public BootstrapControlGroupInputListFromEnum(HtmlHelper html, string htmlFieldName, ModelMetadata metadata, BootstrapInputType inputType) : base(html, htmlFieldName, metadata, inputType) { this._model.displayValidationMessage = true; }
public BootstrapLabelModel() { htmlAttributes = new Dictionary<string, object>(); innerInputType = BootstrapInputType._NotSet; }
public BootstrapInputListLabeled(HtmlHelper html, object inputModel, BootstrapInputType inputType) : base(html, inputModel, inputType) { }
public BootstrapInputLabeled(HtmlHelper html, dynamic inputModel, BootstrapInputType inputType) : base(html, (string)inputModel.htmlFieldName, (ModelMetadata)inputModel.metadata) { this._inputModel = inputModel; this._inputType = inputType; }