public static string RenderFormGroupCustom(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 BootstrapFormGroup(input, label, FormGroupType.textboxLike, fieldIsValid).ToHtmlString());
        }
        public static string RenderControlGroupTextArea(HtmlHelper html, BootstrapTextAreaModel inputModel, BootstrapLabelModel labelModel)
        {
            if (string.IsNullOrEmpty(inputModel.htmlFieldName))
            {
                return(null);
            }

            var input = Renderer.RenderTextArea(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());
        }
Ejemplo n.º 3
0
        public static string RenderLabel(HtmlHelper html, BootstrapLabelModel model)
        {
            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 RenderFormGroupRadioButtonTrueFalse(HtmlHelper html, BootstrapRadioButtonTrueFalseModel inputModel, BootstrapLabelModel labelModel)
        {
            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 BootstrapFormGroup(input, label, FormGroupType.textboxLike, fieldIsValid).ToHtmlString());
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public static string RenderControlGroupDisplayText(HtmlHelper html, BootstrapDisplayTextModel inputModel, BootstrapLabelModel labelModel)
        {
            var input = Renderer.RenderDisplayText(html, inputModel);

            string label = Renderer.RenderLabel(html, labelModel ?? new BootstrapLabelModel
            {
                htmlFieldName    = inputModel.htmlFieldName,
                metadata         = inputModel.metadata,
                htmlAttributes   = new { @class = "control-label" }.ToDictionary(),
                showRequiredStar = false
            });

            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 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());
        }
Ejemplo n.º 8
0
        public static string RenderFormGroupTextBox(HtmlHelper html, BootstrapTextBoxModel inputModel, BootstrapLabelModel labelModel)
        {
            var input   = Renderer.RenderTextBox(html, inputModel, false);
            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,
                htmlAttributes = new { @class = "control-label" + 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, label, FormGroupType.textboxLike, fieldIsValid).ToHtmlString());
        }
Ejemplo n.º 9
0
        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 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());
        }