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)); }
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 selectTag = new SelectTag(); var elementName = CCHtmlConventions2.DeriveElementName(request); selectTag.Attr("data-bind", "options:_" + elementName + "List," + "optionsText:'Text'," + "optionsValue:'Value'," + "value:" + elementName ); return selectTag; }
private HtmlTag ScoreTypeBuilder(ElementRequest request) { var genders = Enum.GetValues(typeof(ScoreType)).Cast<ScoreType>().ToList(); var tag = new SelectTag(t => { genders.Each(g => t.Option(g.ToString(), g)); t.SelectByValue((request.RawValue ?? ScoreType.Time).ToString()); }); return tag; }
private HtmlTag GenderBuilder(ElementRequest request) { var genders = Enum.GetValues(typeof(Gender)).Cast<Gender>().ToList(); var tag = new SelectTag(t => { genders.Each(g => t.Option(g.ToString(), g)); t.SelectByValue((request.RawValue ?? Gender.Male).ToString()); }); return tag; }
private HtmlTag NewSelectList(Type propertyType) { var items = session.CreateCriteria(propertyType).List<IEntity>(); var selectList = new SelectTag(); foreach (var entity in items) { selectList.Option(entity.ToString(), entity.Id); } return selectList; }
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 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"); }
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 selectTag = new SelectTag(); var elementName = CCHtmlConventions2.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; }
private static IHtmlString SelectInternal(string name, IEnumerable<SelectListItem> selectList,IDictionary<string, object> htmlAttributes) { var tag = new SelectTag(x=>SetResult(x,selectList)).Id(name).Attr("name", name); if (htmlAttributes != null) { foreach (var item in htmlAttributes) { tag.Attr(item.Key, item.Value); } } return new NonEncodedHtmlString(tag.ToString()); }
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); }
private static object SetResult(SelectTag x, IEnumerable<SelectListItem> selectList) { foreach (var item in selectList) { if (item.Selected) { x.TopOption(item.Text, item.Value); } else { x.Option(item.Text, item.Value); } } return x; }
public SelectTag(TagInfo tagInfo) : base("select", tagInfo) { HtmlTags.SelectTag tempSelectTag = new HtmlTags.SelectTag(); foreach (string option in tagInfo.ListItems) { tempSelectTag.Option(option, option); } string defaultValue; var tryGetValue = tagInfo.Attributes.TryGetValue("required", out defaultValue); if (tryGetValue && defaultValue.Equals("true")) { tempSelectTag.SelectByValue(defaultValue); } _tag = tempSelectTag; }
public void SelectValue_WithOptions() { var tag = new SelectTag() .AddOption("display0", 0, groupBy: "g0") .AddOption("display1", 1, groupBy: "g0") .SelectValue(0); Assert.True(tag.Children.First().Children.First().HasAttr("selected")); Assert.False(tag.Children.First().Children.Skip(1).First().HasAttr("selected")); }
public void SelectValue_WithOption_UnexistingValue() { var tag = new SelectTag() .AddOption("display0", 0, groupBy: "g0") .SelectValue(1); Assert.False(tag.Children.First().Children.First().HasAttr("selected")); }
public void AddOption_WithOption() { var tag = new SelectTag() .AddOption("display0", 0, groupBy: "g0") .AddOption("display1", 1, groupBy: "g0"); AssertOptionGroups(tag, 1); 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); }