コード例 #1
0
        public void DropDownListRenderer_AppendElement_ForEachOptionInFormPropertyOptionRendererShouldBeCalled()
        {
            var dropDownList = new DropDownList
            {
                Options =
                    new List <FormListOption> {
                    new FormListOption(), new FormListOption(), new FormListOption()
                }
            };

            _dropDownListRenderer.AppendElement(dropDownList, null, FormRenderingType.Bootstrap2);

            A.CallTo(() => _dropDownListOptionRenderer.GetOption(A <FormListOption> .Ignored, null))
            .MustHaveHappened(Repeated.Exactly.Times(3));
        }
コード例 #2
0
        public TagBuilder AppendElement(DropDownList formProperty, string existingValue, FormRenderingType formRenderingType)
        {
            TagBuilder tagBuilder = new TagBuilder("select");

            tagBuilder.Attributes["name"] = formProperty.Name;
            tagBuilder.Attributes["id"]   = formProperty.GetHtmlId();

            if (formProperty.Required)
            {
                tagBuilder.Attributes["data-val"]          = "true";
                tagBuilder.Attributes["data-val-required"] =
                    string.Format("The field {0} is required",
                                  string.IsNullOrWhiteSpace(formProperty.LabelText)
                                      ? formProperty.Name
                                      : formProperty.LabelText);
            }
            if (!string.IsNullOrWhiteSpace(formProperty.CssClass))
            {
                tagBuilder.AddCssClass(formProperty.CssClass);
            }
            if (formRenderingType == FormRenderingType.Bootstrap3)
            {
                tagBuilder.AddCssClass("form-control");
            }

            foreach (FormListOption option in formProperty.Options)
            {
                tagBuilder.InnerHtml += _dropDownListOptionRenderer.GetOption(option, existingValue);
            }
            return(tagBuilder);
        }