示例#1
0
        public HtmlTag FilterCheckboxesTag()
        {
            var allContent = ContentFunction();

            var filterTags = allContent.Select(TypeToFilterTag).Distinct().ToList();

            if (filterTags.Count() < 2)
            {
                return(HtmlTag.Empty());
            }

            var filterContainer = new DivTag().AddClass("content-list-filter-container");

            var textInfo = new CultureInfo("en-US", false).TextInfo;

            foreach (var loopTag in filterTags)
            {
                var itemContainer = new DivTag().AddClass("content-list-filter-item");
                var checkbox      = new CheckboxTag(false).Id($"{loopTag}-content-list-filter-checkbox")
                                    .AddClass("content-list-filter-checkbox").Value(loopTag).Attr("onclick", "searchContent()");
                var label = new HtmlTag("label").AddClass("content-list-filter-checkbox-label")
                            .Text(textInfo.ToTitleCase(loopTag));
                itemContainer.Children.Add(checkbox);
                itemContainer.Children.Add(label);
                filterContainer.Children.Add(itemContainer);
            }

            return(filterContainer);
        }
示例#2
0
        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));
        }
示例#3
0
        public void basic_construction()
        {
            var tag = new CheckboxTag(true);

            tag.TagName().ShouldEqual("input");
            tag.Attr("type").ShouldEqual("checkbox");
        }
示例#4
0
        static HtmlTag GenerateInputCheck <TModel> (TModel model, PropertyInfo member)
        {
            var modelValue = member.GetValue(model, null);

            if (modelValue == null)
            {
                return(null);
            }

            //<div class="control-group">
            //  <label class="control-label" for="Email">Email:</label>
            //  <div class="controls">
            //    <input type="checkbox" class="input-xlarge" data-val="true"
            //        data-val-email="O e-mail digitado não é válido."
            //        data-val-required="O campo E-mail é obrigatório."
            //        id="Email" name="Email" value="@Model.Email">
            //    <span class="field-validation-valid error" data-valmsg-for="Email"
            //        data-valmsg-replace="true"></span>
            //    <p class="help-block">Ex.: [email protected]</p>
            //  </div>
            //</div>

            var cg = CreateControlGroup(model, member);

            var input = new CheckboxTag((bool)modelValue)
                        .Attr("name", member.Name)
                        .Id(member.Name);

            FillValidation <TModel> (input, member);

            cg.Children [1].InsertFirst(input);

            return(cg);
        }
示例#5
0
 public MvcCheckboxElement(string id, string name, bool isChecked) : base("")
 {
     NoTag();
     Tag = new CheckboxTag(isChecked);
     Tag.Id(id).Name(name);
     if (isChecked)
     {
         Tag
         .Attr("checked", "checked")
         ;
     }
     Tag.Value("true");
     Append(Tag);
     Append(new HiddenTag().Name(name).Value("false"));
 }
        private static HtmlTag BuildCheckBox(ElementRequest request)
        {
            var namingConvention = new DotNotationElementNamingConvention();
            var name             = namingConvention.GetName(request.HolderType(), request.Accessor);

            var checkboxTag = new CheckboxTag(request.Value <bool>())
                              .Attr("value", "true")
                              .Attr("name", name)
                              .Attr("id", name);

            var mvcConventionHiddenInput = new HiddenTag()
                                           .Attr("value", "false")
                                           .Attr("name", name);

            checkboxTag.After(mvcConventionHiddenInput);
            return(checkboxTag);
        }
        public DefaultHtmlConventions()
        {
            Displays.Always.BuildBy(req => new HtmlTag("span").Text(req.GetValue <string>()));
            Labels.Always.BuildBy(req => new HtmlTag("label").Attr("for", req.Id).Text(req.Accessor.InnerProperty.Name.BreakUpCamelCase()));
            Inputs.Always.BuildBy(req =>
            {
                return(new TextboxTag().Attr("value", req.GetAttemptedValue() ?? req.GetValue <string>()));
            });

            Inputs.If <bool>().BuildBy(req =>
            {
                var attemptedVal = req.GetAttemptedValue();
                var isChecked    = attemptedVal != null ? attemptedVal.Split(',').First() == Boolean.TrueString: req.GetValue <bool>();
                var check        = new CheckboxTag(isChecked).Attr("value", true);
                var hidden       = new HiddenTag().Attr("name", req.Name).Attr("value", false);
                return(check.After(hidden));
            });

            Inputs.If <IEnumerable <SelectListItem> >().BuildBy(BuildSelectList);
            Inputs.If <MultiSelectList>().BuildBy(BuildSelectList);

            All.Always.Modify((h, r) =>
            {
                h.Id((string.IsNullOrEmpty(r.Id) ? null : r.Id) ?? (string.IsNullOrEmpty(h.Id()) ? null : h.Id()));
                if (h.IsInputElement())
                {
                    h.Attr("name", r.Name ?? (string.IsNullOrEmpty(h.Attr("name")) ? null : h.Attr("name")));
                }
            });

            Labels.Always.Modify((h, r) => h.Id(r.Id + "_" + "Label"));
            Displays.Always.Modify((h, r) => h.Id(r.Id + "_" + "Display"));

            Inputs.Always.Modify((h, r) =>
            {
                //Validation class
                ModelStateEntry modelState;
                if (r.ViewContext.ViewData.ModelState.TryGetValue(r.Name, out modelState) && modelState.Errors.Count > 0)
                {
                    h.AddClass(HtmlHelper.ValidationInputCssClassName);
                }
            });
        }
 public void create_checkbox_that_is_not_checked()
 {
     var tag = new CheckboxTag(false);
     tag.HasAttr("checked").ShouldBeFalse();
 }
 public void create_checkbox_that_is_checked()
 {
     var tag = new CheckboxTag(true);
     tag.Attr("checked").ShouldEqual("true");
 }
示例#10
0
 public void basic_construction()
 {
     var tag = new CheckboxTag(true);
     tag.TagName().ShouldEqual("input");
     tag.Attr("type").ShouldEqual("checkbox");
 }
示例#11
0
        public void create_checkbox_that_is_not_checked()
        {
            var tag = new CheckboxTag(false);

            tag.HasAttr("checked").ShouldBeFalse();
        }
示例#12
0
        public void create_checkbox_that_is_checked()
        {
            var tag = new CheckboxTag(true);

            tag.Attr("checked").ShouldEqual("true");
        }