public void PrependOption_WithOption_MultipleGroups() { var tag = new SelectTag() .AddOption("display1", 1, groupBy: "g0") .PrependOption("display0", 0, groupBy: "g0") .AddOption("display2", 2, groupBy: "g1"); AssertOptionGroups(tag, 2); var optgroup0 = tag.Children.First(); AssertOptionGroup(optgroup0, "g0"); Assert.Equal(2, optgroup0.Children.Count()); var option0 = optgroup0.Children.Skip(0).First(); AssertOption(option0, "display0", 0); var option1 = optgroup0.Children.Skip(1).First(); AssertOption(option1, "display1", 1); var optgroup1 = tag.Children.Skip(1).First(); AssertOptionGroup(optgroup1, "g1"); Assert.Equal(1, optgroup1.Children.Count()); var option2 = optgroup1.Children.Skip(0).First(); AssertOption(option2, "display2", 2); }
public override HtmlTag Build(ElementRequest request) { var aca = request.Get <IActionContextAccessor>(); var teamId = int.Parse((string)aca.ActionContext.RouteData.Values["teamId"]); var db = request.Get <SupportManagerContext>(); var results = db.TeamMembers.Where(m => m.TeamId == teamId).SelectMany(m => m.User.PhoneNumbers) .Select(upn => new { upn.User.DisplayName, upn.Id, upn.Value }).OrderBy(upn => upn.DisplayName).ToList(); var selectTag = new SelectTag(t => { t.Option(string.Empty, string.Empty); // blank default option foreach (var result in results) { t.Option($"{result.DisplayName} - {result.Value}", result.Id); } }); var entity = request.Value <UserPhoneNumber>(); if (entity != null) { selectTag.SelectByValue(entity.Id); } return(selectTag); }
public void AddOptions_Enum_SelectedValues() { var tag = new SelectTag() .AddOptions( OptionsList.CreateForEnum <Enum1>() .SelectedValues(new string[] { Enum1.Option2.ToString() }) .Configure((x, op) => op.Data("customdata", x.Value))); Assert.Equal(2, tag.Children.Count()); var firstChild = tag.Children.First(); var secondChild = tag.Children.Skip(1).First(); Assert.Equal("Option1", firstChild.Text()); Assert.True(firstChild.ValueIsEqual(Enum1.Option1.ToString())); Assert.False(firstChild.HasAttr("selected")); Assert.Equal(1, firstChild.Data("customdata")); Assert.Equal("Option2", secondChild.Text()); Assert.True(secondChild.ValueIsEqual(Enum1.Option2.ToString())); Assert.True(secondChild.HasAttr("selected")); Assert.Equal(2, secondChild.Data("customdata")); }
public DefaultAspNetMvcHtmlConventions() { Editors.IfPropertyIs <bool>().BuildBy(req => { var check = new CheckboxTag(req.Value <bool>()).Attr("value", req.StringValue()); var hidden = new HiddenTag().Attr("name", req.ElementId).Attr("value", false); return(check.Append(hidden)); }); Editors.IfPropertyIs <IEnumerable <SelectListItem> >().BuildBy(req => { var list = req.Value <IEnumerable <SelectListItem> >(); var drop = new SelectTag(); foreach (var item in list) { drop.Add("option").Attr("value", item.Value).Attr("selected", item.Selected).Text(item.Text); } return(drop); }); Editors.Always.ModifyWith(AddElementName); //Editors.Always.BuildBy(TagActionExpression.BuildTextbox); //Displays.Always.BuildBy(req => new HtmlTag("span").Text(req.StringValue())); //Labels.Always.BuildBy(req => new HtmlTag("span").Text(req.Accessor.Name)); }
private static void SetSelectedValue(ElementRequest request, SelectTag select) { if (!request.ValueIsEmpty()) { select.SelectByValue(request.Value <int>().ToString()); } }
public static HtmlTag OptionGroup(this SelectTag tag, string display) { HtmlTag option = tag.MakeOptionGroup(display); tag.Append(option); return(option); }
private static void SetSelectedValue(ElementRequest request, SelectTag select) { if (!request.ValueIsEmpty()) { select.SelectByValue(request.Value<int>().ToString()); } }
public void AddOptions_Enum_Localized() { var prevResource = Resources.Current; try { Resources.Register(new TypedClassResourceProvider(typeof(Enum1Resources))); var tag = new SelectTag() .AddOptions( OptionsList.CreateForEnum <Enum1>() .SelectedValue(Enum1.Option2.ToString()) .Configure((x, op) => op.Data("customdata", x.Value))); Assert.Equal(2, tag.Children.Count()); var firstChild = tag.Children.First(); var secondChild = tag.Children.Skip(1).First(); Assert.Equal("Option 1", firstChild.Text()); Assert.True(firstChild.ValueIsEqual(Enum1.Option1.ToString())); Assert.False(firstChild.HasAttr("selected")); Assert.Equal(1, firstChild.Data("customdata")); Assert.Equal("Option2", secondChild.Text()); Assert.True(secondChild.ValueIsEqual(Enum1.Option2.ToString())); Assert.True(secondChild.HasAttr("selected")); Assert.Equal(2, secondChild.Data("customdata")); } finally { Resources.Register(prevResource); } }
private static void SetSelectedValue(ElementRequest request, SelectTag select) { if (request.RawValue != null) { select.SelectByValue(request.RawValue.ToString()); } }
private static void AddOptionalBlankOption(ElementRequest request, SelectTag select) { var hasBlankOption = request.Accessor.HasAttribute<WithBlankOption>(); if (hasBlankOption) { select.Option(string.Empty, string.Empty); } }
public void SelectValue_WithOption() { var tag = new SelectTag() .AddOption("display0", 0, groupBy: "g0") .SelectValue(0); Assert.True(tag.Children.First().Children.First().HasAttr("selected")); }
public HtmlForm(MySe74Context context) : base(context) { FormLink = new Se74Element(By.XPath("//a[.='HTML Forms']")); FirstName = new TextInput(By.Name("first_name")); LastName = new TextInput(By.Name("first_name")); Maths = new CheckBox(By.Name("maths")); Physics = new CheckBox(By.Name("physics")); Dropdown = new SelectTag(By.Name("dropdown")); }
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); } }
public void can_initialize_options_in_constructor() { var select = new SelectTag(tag => { tag.Option("a", "1"); tag.Option("b", "2"); tag.Option("c", "3"); }); select.Children.Select(t => t.Text()).ShouldHaveTheSameElementsAs(new[]{"a", "b", "c"}); }
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"); }
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"); }
private void AssertOptionGroups( SelectTag tag, int groupsCount) { Assert.Equal(groupsCount, tag.Children.Count()); Assert.Equal(groupsCount, tag.OptionGroups.Count()); Assert.True(tag.OptionGroups.Values.All(g => tag.Children.Any(c => c == g))); Assert.Equal(tag.Children.SelectMany(x => x.Children).Count(), tag.Options.Count()); Assert.True(tag.Options.All(g => tag.Children.SelectMany(x => x.Children).Any(c => c == g))); }
public void can_initialize_options_in_constructor() { var select = new SelectTag(tag => { tag.Option("a", "1"); tag.Option("b", "2"); tag.Option("c", "3"); }); select.Children.Select(t => t.Text()).ShouldHaveTheSameElementsAs(new[] { "a", "b", "c" }); }
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 AddOption_Empty() { var tag = new SelectTag() .AddOption("display0", 0); Assert.Equal(1, tag.Children.Count()); var firstChild = tag.Children.First(); Assert.Equal("display0", firstChild.Text()); Assert.True(firstChild.ValueIsEqual(0)); }
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 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 add_element_name_to_select() { var select = new SelectTag(); ElementRequest request = For(x => x.Address.City); request.ElementId = "AddressCity"; DefaultHtmlConventions.AddElementName(request, select); select.Attr("name").ShouldEqual("AddressCity"); }
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 override HtmlTag Build(ElementRequest request) { var selectTag = new SelectTag(); var elementName = CCHtmlConventionsKO.DeriveElementName(request); var elementRoot = elementName.Contains("EntityId") ? elementName.Replace(".EntityId", "") : elementName; selectTag.Attr("data-bind", "options:_" + elementRoot + "List," + "optionsValue:'Value'," + "optionsText:'Text'," + "value:" + elementName); return(selectTag); }
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 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; }
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(); }
public void SelectValue_WithOption_UnexistingValue() { var tag = new SelectTag() .AddOption("display0", 0) .SelectValue(1); Assert.Equal(1, tag.Children.Count()); var firstChild = tag.Children.First(); Assert.Equal("display0", firstChild.Text()); Assert.True(firstChild.ValueIsEqual(0)); Assert.False(firstChild.HasAttr("selected")); }
/// <summary> /// Marks the selected options from the values in the selected parameter /// </summary> public static SelectTag SelectValues(this SelectTag tag, IEnumerable selected) { foreach (var value in selected) { // TODO Is there a better way to do this? Generics? It also impacts the CheckBoxBuilder. var stringValue = value.ToString(); // default to just writing string value of object ExceptionHelpers.IgnoreExceptions(() => stringValue = ((int)value).ToString()); // trys to cast value as an int. var optionTag = tag.Children.FirstOrDefault(x => x.Attr(HtmlAttributeConstants.Value).Equals(stringValue)); if (optionTag != null) { optionTag.Attr(HtmlAttributeConstants.Selected, HtmlAttributeConstants.Selected); } } return(tag); }
public void AddOptions_CustomItems_Empty() { var items = new List <CustomItem>(); var tag = new SelectTag() .AddOptions( OptionsList.Create( items, display: x => x.Display, value: x => x.Value) .IsSelected(x => x.IsSelected) .Configure((x, op) => op.Data("customdata", x.Value))); Assert.Equal(0, tag.Children.Count()); }
public void PrependOption_Empty() { var tag = new SelectTag() .PrependOption("display0", 0, groupBy: "g0"); AssertOptionGroups(tag, 1); var optgroup0 = tag.Children.First(); AssertOptionGroup(optgroup0, "g0"); Assert.Equal(1, optgroup0.Children.Count()); var option0 = optgroup0.Children.First(); AssertOption(option0, "display0", 0); }
public void AddOption_WithOption() { var tag = new SelectTag() .AddOption("display0", 0) .AddOption("display1", 1); Assert.Equal(2, tag.Children.Count()); var firstChild = tag.Children.First(); var secondChild = tag.Children.Skip(1).First(); Assert.Equal("display0", firstChild.Text()); Assert.True(firstChild.ValueIsEqual(0)); Assert.Equal("display1", secondChild.Text()); Assert.True(secondChild.ValueIsEqual(1)); }
public void SelectValue_WithOptions_SameAlreadySelected() { var tag = new SelectTag() .AddOption("display0", 0) .AddOption("display1", 1) .SelectValue(0) .SelectValue(0); Assert.Equal(2, tag.Children.Count()); var firstChild = tag.Children.First(); var secondChild = tag.Children.Skip(1).First(); Assert.Equal("display0", firstChild.Text()); Assert.True(firstChild.ValueIsEqual(0)); Assert.True(firstChild.HasAttr("selected")); Assert.Equal("display1", secondChild.Text()); Assert.True(secondChild.ValueIsEqual(1)); Assert.False(secondChild.HasAttr("selected")); }
public void AddOptions_CustomItems() { var items = new List<CustomItem>() { new CustomItem() { Display = "display0", Value = 0, IsSelected = false }, new CustomItem() { Display = "display1", Value = 1, IsSelected = true }, new CustomItem() { Display = "display2", Value = 2, IsSelected = false }, }; var tag = new SelectTag() .AddOptions( OptionsList.Create( items, display: x => x.Display, value: x => x.Value) .IsSelected(x => x.IsSelected) .Configure((x, op) => op.Data("customdata", x.Value))); Assert.Equal(3, tag.Children.Count()); var firstChild = tag.Children.First(); var secondChild = tag.Children.Skip(1).First(); var thirdChild = tag.Children.Skip(2).First(); Assert.Equal("display0", firstChild.Text()); Assert.True(firstChild.ValueIsEqual(0)); Assert.False(firstChild.HasAttr("selected")); Assert.Equal(0, firstChild.Data("customdata")); Assert.Equal("display1", secondChild.Text()); Assert.True(secondChild.ValueIsEqual(1)); Assert.True(secondChild.HasAttr("selected")); Assert.Equal(1, secondChild.Data("customdata")); Assert.Equal("display2", thirdChild.Text()); Assert.True(thirdChild.ValueIsEqual(2)); Assert.False(thirdChild.HasAttr("selected")); Assert.Equal(2, thirdChild.Data("customdata")); }
public void AddOptions_CustomItems_Empty() { var items = new List<CustomItem>(); var tag = new SelectTag() .AddOptions( OptionsList.Create( items, display: x => x.Display, value: x => x.Value) .IsSelected(x => x.IsSelected) .Configure((x, op) => op.Data("customdata", x.Value))); Assert.Equal(0, tag.Children.Count()); }
public void AddOptions_Enum_Localized() { var prevResource = Resources.Current; try { Resources.Register(new TypedClassResourceProvider(typeof(Enum1Resources))); var tag = new SelectTag() .AddOptions( OptionsList.CreateForEnum<Enum1>() .SelectedValue(2) .Configure((x, op) => op.Data("customdata", x.Value))); Assert.Equal(2, tag.Children.Count()); var firstChild = tag.Children.First(); var secondChild = tag.Children.Skip(1).First(); Assert.Equal("Option 1", firstChild.Text()); Assert.True(firstChild.ValueIsEqual(1)); Assert.False(firstChild.HasAttr("selected")); Assert.Equal(1, firstChild.Data("customdata")); Assert.Equal("Option2", secondChild.Text()); Assert.True(secondChild.ValueIsEqual(2)); Assert.True(secondChild.HasAttr("selected")); Assert.Equal(2, secondChild.Data("customdata")); } finally { Resources.Register(prevResource); } }
public void AddOptions_Enum_SelectedValues() { var tag = new SelectTag() .AddOptions( OptionsList.CreateForEnum<Enum1>() .SelectedValues(Coll.Array(2)) .Configure((x, op) => op.Data("customdata", x.Value))); Assert.Equal(2, tag.Children.Count()); var firstChild = tag.Children.First(); var secondChild = tag.Children.Skip(1).First(); Assert.Equal("Option1", firstChild.Text()); Assert.True(firstChild.ValueIsEqual(1)); Assert.False(firstChild.HasAttr("selected")); Assert.Equal(1, firstChild.Data("customdata")); Assert.Equal("Option2", secondChild.Text()); Assert.True(secondChild.ValueIsEqual(2)); Assert.True(secondChild.HasAttr("selected")); Assert.Equal(2, secondChild.Data("customdata")); }
public void SelectValue_Empty() { var tag = new SelectTag().SelectValue(1); Assert.Equal(0, tag.Children.Count()); }