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"); }
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(); }
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(); }
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(); }
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(); }
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); } }
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 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); }
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; }
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))); }