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_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_remove_previous_selected_value() { var tag = new SelectTag(); tag.Option("a", "1"); tag.Option("b", "2"); tag.Option("c", "3"); tag.SelectByValue("2"); tag.SelectByValue("1"); tag.Children[0].Attr("selected").ShouldBe("selected"); tag.Children[1].HasAttr("selected").ShouldBeFalse(); tag.Children[2].HasAttr("selected").ShouldBeFalse(); }
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); }
private static void SetSelectedValue(ElementRequest request, SelectTag select) { if (!request.ValueIsEmpty()) { select.SelectByValue(request.Value <int>().ToString()); } }
private static void SetSelectedValue(ElementRequest request, SelectTag select) { if (!request.ValueIsEmpty()) { select.SelectByValue(request.Value<int>().ToString()); } }
private static void SetSelectedValue(ElementRequest request, SelectTag select) { if (request.RawValue != null) { select.SelectByValue(request.RawValue.ToString()); } }
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 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_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 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); }
/// <summary> /// Creates and returns a select tag (dropdown box) having the enumeration as options /// </summary> /// <typeparam name="T"></typeparam> /// <param name="options"></param> /// <param name="setOption"></param> /// <param name="selectedValue"></param> /// <returns></returns> public static SelectTag ToSelectTag <T>(this IEnumerable <T> options, Action <SelectTag, T> setOption, object selectedValue = null) { options.MustNotBeNull(); setOption.MustNotBeNull(); var tag = new SelectTag(); foreach (var option in options) { setOption(tag, option); } if (selectedValue != null) { tag.SelectByValue(selectedValue); } return(tag); }
public override HtmlTag Build(ElementRequest request) { var results = Source(request); var selectTag = new SelectTag(t => { t.Option(string.Empty, string.Empty); // blank default option foreach (var result in results) { BuildOptionTag(t, result, request); } }); var entity = request.Value <T>(); if (entity != null) { selectTag.SelectByValue(GetValue(entity)); } return(selectTag); }
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; }
private static void SetSelectedValue(ElementRequest request, SelectTag select) { if (request.RawValue != null) { select.SelectByValue(request.RawValue.ToString()); } }