示例#1
0
        public void should_add_default_option_to_top_of_list()
        {
            var tag = new SelectTag();
            tag.Option("a", "1");
            tag.Option("b", "2");

            tag.DefaultOption("bar");

            tag.Children[0].Text().ShouldEqual("bar");
        }
示例#2
0
        public void should_add_default_option_to_top_of_list()
        {
            var tag = new SelectTag();

            tag.Option("a", "1");
            tag.Option("b", "2");

            tag.DefaultOption("bar");

            tag.Children[0].Text().ShouldEqual("bar");
        }
示例#3
0
        public void should_not_remove_previous_selected_value_if_new_value_is_bogus()
        {
            var tag = new SelectTag();
            tag.Option("a", "1");
            tag.Option("b", "2");

            tag.SelectByValue("1");
            tag.SelectByValue("abcd");

            tag.Children[0].Attr("selected").ShouldEqual("selected");
            tag.Children[1].HasAttr("selected").ShouldBeFalse();
        }
示例#4
0
        public void should_make_the_default_option_selected()
        {
            var tag = new SelectTag();
            tag.Option("a", "1");
            tag.Option("b", "2");

            tag.DefaultOption("bar");

            tag.Children[0].Attr("selected").ShouldEqual("selected");
            tag.Children[1].HasAttr("selected").ShouldBeFalse();
            tag.Children[2].HasAttr("selected").ShouldBeFalse();
        }
示例#5
0
        public void should_not_remove_previous_selected_value_if_new_value_is_bogus()
        {
            var tag = new SelectTag();

            tag.Option("a", "1");
            tag.Option("b", "2");

            tag.SelectByValue("1");
            tag.SelectByValue("abcd");

            tag.Children[0].Attr("selected").ShouldEqual("selected");
            tag.Children[1].HasAttr("selected").ShouldBeFalse();
        }
示例#6
0
        public void selected_by_value()
        {
            var tag = new SelectTag();
            tag.Option("a", "1");
            tag.Option("b", "2");
            tag.Option("c", "3");

            tag.SelectByValue("2");

            tag.Children[0].HasAttr("selected").ShouldBeFalse();
            tag.Children[1].Attr("selected").ShouldEqual("selected");
            tag.Children[2].HasAttr("selected").ShouldBeFalse();
        }
示例#7
0
        public void should_make_the_default_option_selected()
        {
            var tag = new SelectTag();

            tag.Option("a", "1");
            tag.Option("b", "2");

            tag.DefaultOption("bar");

            tag.Children[0].Attr("selected").ShouldEqual("selected");
            tag.Children[1].HasAttr("selected").ShouldBeFalse();
            tag.Children[2].HasAttr("selected").ShouldBeFalse();
        }
示例#8
0
        public void selected_by_value()
        {
            var tag = new SelectTag();

            tag.Option("a", "1");
            tag.Option("b", "2");
            tag.Option("c", "3");

            tag.SelectByValue("2");

            tag.Children[0].HasAttr("selected").ShouldBeFalse();
            tag.Children[1].Attr("selected").ShouldBe("selected");
            tag.Children[2].HasAttr("selected").ShouldBeFalse();
        }
示例#9
0
        public void selected_by_string_value()
        {
            var tag = new SelectTag();

            tag.Option("a", 1);
            tag.Option("b", 2);
            tag.Option("c", 3);

            tag.SelectByValue(2);

            tag.Children[0].HasAttr("selected").ShouldBeFalse();
            tag.Children[1].Attr("selected").ShouldEqual("selected");
            tag.Children[2].HasAttr("selected").ShouldBeFalse();
        }
 private static void AddOptionalBlankOption(ElementRequest request, SelectTag select)
 {
     var hasBlankOption = request.Accessor.HasAttribute<WithBlankOption>();
     if (hasBlankOption)
     {
         select.Option(string.Empty, string.Empty);
     }
 }
 private static void AddOptions(ElementRequest request, SelectTag select)
 {
     var from = GetOptionsFromAttribute(request);
     var optionPairs = GetOptionPairs(request, from);
     foreach (var item in optionPairs)
     {
         select.Option(item.Text, item.Value);
     }
 }
        private static void AddOptionalBlankOption(ElementRequest request, SelectTag select)
        {
            var hasBlankOption = request.Accessor.HasAttribute <WithBlankOption>();

            if (hasBlankOption)
            {
                select.Option(string.Empty, string.Empty);
            }
        }
 private void AddOptions(ElementRequest request, SelectTag select)
 {
     var options = GetOptions(request);
     foreach (var option in options)
     {
         var text = GetText(option);
         var value = option.GetRawConstantValue().ToString();
         select.Option(text, value);
     }
 }
示例#14
0
        private static void AddOptions(ElementRequest request, SelectTag select)
        {
            var from        = GetOptionsFromAttribute(request);
            var optionPairs = GetOptionPairs(request, from);

            foreach (var item in optionPairs)
            {
                select.Option(item.Text, item.Value);
            }
        }
示例#15
0
        public void FirstOption_should_prepend_new_option_at_top()
        {
            var tag = new SelectTag();
            tag.Option("a", "1");

            tag.TopOption("_", "0");

            tag.Children[0].Text().ShouldEqual("_");
            tag.Children[1].Text().ShouldEqual("a");
        }
示例#16
0
        public void FirstOption_should_prepend_new_option_at_top()
        {
            var tag = new SelectTag();

            tag.Option("a", "1");

            tag.TopOption("_", "0");

            tag.Children[0].Text().ShouldEqual("_");
            tag.Children[1].Text().ShouldEqual("a");
        }
        private void AddOptions(ElementRequest request, SelectTag select)
        {
            var options = GetOptions(request);

            foreach (var option in options)
            {
                var text  = GetText(option);
                var value = option.GetRawConstantValue().ToString();
                select.Option(text, value);
            }
        }
        private static void buildOptions(ElementRequest request, SelectTag tag)
        {
            var listElements = GetListElementTitlesOrderedByRank(request);

            listElements.ElementTitles.Each(title => tag.Option(title, title));

            var requestValue = request.Value <string>();

            var defaultValue = requestValue.IsNotEmpty() ? requestValue : listElements.DefaultElementTitle;

            tag.SelectByValue(defaultValue);
        }
示例#19
0
            public override HtmlTag Build(ElementRequest request)
            {
                var enumType = request.Accessor.PropertyType;

                var select = new SelectTag();

                foreach (var value in Enum.GetValues(enumType))
                {
                    select.Option(Enum.GetName(enumType, value), value);
                }
                select.SelectByValue(request.RawValue);

                return select;
            }
示例#20
0
            public override HtmlTag Build(ElementRequest request)
            {
                var enumType = request.Accessor.PropertyType;

                var select = new SelectTag();

                foreach (var value in Enum.GetValues(enumType))
                {
                    select.Option(Enum.GetName(enumType, value), value);
                }
                select.SelectByValue(request.RawValue);

                return(select);
            }
 protected virtual HtmlTag BuildOptionTag(SelectTag select, T model, ElementRequest request)
 {
     return(select.Option(GetDisplayValue(model), GetValue(model)));
 }