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 HtmlTag Checkbox(UIComponentContext context)
 {
     var checkbox = new CheckboxTag(context.Value<bool>()).Attr("value", "true");
     var hidden = new HtmlTag("input").Attr("type", "hidden").Attr("value", "false");
     checkbox.Next = hidden;
     return checkbox;
 }
 public static HtmlTag CheckBoxBuilder(ElementRequest request)
 {
     var isChecked = request.Value<bool>();
     var tag = new CheckboxTag(isChecked);
     tag.Attr("name", request.Accessor.Name);
     tag.AddClass("checkbox");
     return tag;
 }
Ejemplo n.º 4
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"));
 }
Ejemplo n.º 5
0
        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
                ModelState modelState;
                if (r.ViewContext.ViewData.ModelState.TryGetValue(r.Name, out modelState) && modelState.Errors.Count > 0)
                {
                    h.AddClass(HtmlHelper.ValidationInputCssClassName);
                }
            });
        }