Пример #1
0
 public AnyContent BeginControls(IBootstrapContext context)
 {
     this.WriteSelfStart(context.Writer, context);
     var area = context.CreateWriter<FormGroupControls, AnyContent>().WithoutLabel(LabelValue == null).BeginContent();
     area.OnDisposing(() => WriteSelfEnd(context.Writer, context));
     return area;
 }
Пример #2
0
        public AnyContent BeginControls(IBootstrapContext context)
        {
            this.WriteSelfStart(context.Writer, context);
            var area = context.CreateWriter <FormGroupControls, AnyContent>().WithoutLabel(LabelValue == null).BeginContent();

            area.OnDisposing(() => WriteSelfEnd(context.Writer, context));
            return(area);
        }
Пример #3
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var form = context.PeekNearest <IFormContext>();
            var tb   = context.CreateTagBuilder("div");

            tb.AddCssClass("form-group");
            if (ControlContextValue != null)
            {
                if (ControlContextValue.HasErrors)
                {
                    tb.AddCssClass("has-error");
                }
                else if (ControlContextValue.HasWarning)
                {
                    tb.AddCssClass("has-warning");
                }
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            context.Push(this);

            if (LabelValue != null)
            {
                LabelValue.WriteTo(writer, context);
            }

            if (ControlValue != null)
            {
                using (context.CreateWriter <FormGroupControls, AnyContent>().WithoutLabel(LabelValue == null).BeginContent(writer))
                {
                    ControlValue.WriteTo(writer, context);
                }
            }

            if (form != null && form.TypeValue == FormType.Inline)
            {
                return("</div> "); // trailing space is important for inline forms! Bootstrap does not provide spacing between groups in css!
            }

            return("</div>");
        }
Пример #4
0
        protected override void WriteSelf(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var contextOfT       = (IBootstrapContext <TModel>)context;
            var validationResult = contextOfT.ValidationResult;

            if (validationResult.IsValid)
            {
                return;
            }

            var haveErrors =
                validationResult.ModelErrors.Any(x => !x.IsWarning) ||
                (!HidePropertyErrorsValue && validationResult.PropertyErrors.Any(x => x.Value.Any(y => !y.IsWarning)));
            var haveWarnings =
                validationResult.ModelErrors.Any(x => x.IsWarning) ||
                (!HidePropertyErrorsValue && validationResult.PropertyErrors.Any(x => x.Value.Any(y => y.IsWarning)));

            string msg;

            if (haveErrors)
            {
                using (context.CreateWriter <Alert, AnyContent>().Type(AlertType.DangerRed).BeginContent(writer))
                {
                    msg = context.GetMessage(MessageType.ValidationResultErrorsFoundHeader);
                    if (!string.IsNullOrEmpty(msg))
                    {
                        context.CreateWriter <OrdinaryElement, AnyContent>().TagName("h4").Content(msg).WriteTo(writer, context);
                    }
                    writer.Write("<ul>");
                    foreach (var err in validationResult.ModelErrors.Where(x => !x.IsWarning))
                    {
                        writer.Write("<li>");
                        writer.Write(context.HtmlEncode(err.Message));
                        writer.Write("</li>");
                    }
                    foreach (var err in validationResult.PropertyErrors.SelectMany(x => x.Value.Where(y => !y.IsWarning)))
                    {
                        writer.Write("<li>");
                        writer.Write(context.HtmlEncode(err.Message));
                        writer.Write("</li>");
                    }
                    writer.Write("</ul>");
                    msg = context.GetMessage(MessageType.ValidationResultErrorsFoundFooter);
                    if (!string.IsNullOrEmpty(msg))
                    {
                        context.CreateWriter <OrdinaryElement, AnyContent>().TagName("p").Content(msg).WriteTo(writer, context);
                    }
                }
            }

            if (haveWarnings)
            {
                using (context.CreateWriter <Alert, AnyContent>().Type(AlertType.WarningOrange).BeginContent(writer))
                {
                    msg = context.GetMessage(MessageType.ValidationResultWarningnsFoundHeader);
                    if (!string.IsNullOrEmpty(msg))
                    {
                        context.CreateWriter <OrdinaryElement, AnyContent>().TagName("h4").Content(msg).WriteTo(writer, context);
                    }
                    writer.Write("<ul>");
                    foreach (var err in validationResult.ModelErrors.Where(x => x.IsWarning))
                    {
                        writer.Write("<li>");
                        writer.Write(context.HtmlEncode(err.Message));
                        writer.Write("</li>");
                    }
                    foreach (var err in validationResult.PropertyErrors.SelectMany(x => x.Value.Where(y => y.IsWarning)))
                    {
                        writer.Write("<li>");
                        writer.Write(context.HtmlEncode(err.Message));
                        writer.Write("</li>");
                    }
                    writer.Write("</ul>");
                    msg = context.GetMessage(MessageType.ValidationResultWarningnsFoundFooter);
                    if (!string.IsNullOrEmpty(msg))
                    {
                        context.CreateWriter <OrdinaryElement, AnyContent>().TagName("p").Content(msg).WriteTo(writer, context);
                    }
                }
            }
        }
 private static IWriter2<SelectOption, AnyContent> SelectListItemToSelectOption(IBootstrapContext context, SelectListItem item)
 {
     return context.CreateWriter<SelectOption, AnyContent>().Value(item.Value).Disabled(item.Disabled).Content(item.Text);
 }
Пример #6
0
 private static IWriter2 <SelectOption, AnyContent> SelectListItemToSelectOption(IBootstrapContext context, SelectListItem item)
 {
     return(context.CreateWriter <SelectOption, AnyContent>().Value(item.Value).Disabled(item.Disabled).Content(item.Text));
 }
Пример #7
0
        protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context)
        {
            var form = context.PeekNearest<IFormContext>();
            var tb = context.CreateTagBuilder("div");
            tb.AddCssClass("form-group");
            if (ControlContextValue != null)
            {
                if (ControlContextValue.HasErrors)
                {
                    tb.AddCssClass("has-error");
                }
                else if (ControlContextValue.HasWarning)
                {
                    tb.AddCssClass("has-warning");
                }
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);

            context.Push(this);

            if (LabelValue != null)
            {
                LabelValue.WriteTo(writer, context);
            }

            if (ControlValue != null)
            {
                using (context.CreateWriter<FormGroupControls, AnyContent>().WithoutLabel(LabelValue == null).BeginContent(writer))
                {
                    ControlValue.WriteTo(writer, context);
                }
            }

            if (form != null && form.TypeValue == FormType.Inline)
            {
                return "</div> "; // trailing space is important for inline forms! Bootstrap does not provide spacing between groups in css!
            }

            return "</div>";
        }