protected override void WriteSelf(System.IO.TextWriter writer, IBootstrapContext context) { if (value == null) { return; } var block = value as IWritable; if (block != null) { block.WriteTo(writer, context); return; } var str = value as string; if (str != null) { if (writeWithoutEncoding) { writer.Write(str); } else { writer.Write(context.HtmlEncode(str)); } return; } writer.Write(value); }
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); } } } }
protected override void WriteSelf(System.IO.TextWriter writer, IBootstrapContext context) { var form = context.PeekNearest <IFormContext>(); var formGroup = context.PeekNearest <FormGroup>(); if (formGroup != null && ControlContextValue == null) { ControlContextValue = formGroup.ControlContextValue; } ITagBuilder div = null; if (!SizeValue.IsEmpty()) { // Inline forms does not support sized controls (we need 'some other' sizing rules?) if (form != null && form.TypeValue != FormType.Inline) { if (formGroup != null && formGroup.WithSizedControlValue) { div = context.CreateTagBuilder("div"); div.AddCssClass(SizeValue.ToCssClass()); writer.Write(div.GetStartTag()); } else { throw new InvalidOperationException("Size not allowed - call WithSizedControls() on FormGroup."); } } } var tb = context.CreateTagBuilder("textarea"); tb.AddCssClass("form-control"); if (RowsValue != 0) { tb.MergeAttribute("rows", RowsValue.ToString(CultureInfo.InvariantCulture)); } if (ControlContextValue != null) { tb.MergeAttribute("id", ControlContextValue.Name); tb.MergeAttribute("name", ControlContextValue.Name); if (ControlContextValue.IsRequired) { tb.MergeAttribute("required", "required"); } } if (DisabledValue) { tb.MergeAttribute("disabled", "disabled"); } ApplyCss(tb); ApplyAttributes(tb); writer.Write(tb.GetStartTag()); if (ControlContextValue != null && ControlContextValue.Value != null) { writer.Write(context.HtmlEncode(ControlContextValue.Value.ToString())); } writer.Write(tb.GetEndTag()); if (div != null) { writer.Write(div.GetEndTag()); } }
protected override void WriteSelf(System.IO.TextWriter writer, IBootstrapContext context) { var formGroup = context.PeekNearest <FormGroup>(); if (formGroup != null && ControlContextValue == null) { ControlContextValue = formGroup.ControlContextValue; } ITagBuilder div = null; if (!InlineValue) { div = context.CreateTagBuilder("div"); div.AddCssClass("checkbox"); div.WriteStartTag(writer); } var lbl = context.CreateTagBuilder("label"); if (InlineValue) { lbl.AddCssClass("checkbox-inline"); } lbl.WriteStartTag(writer); var input = context.CreateTagBuilder("input"); input.MergeAttribute("type", "checkbox"); if (ControlContextValue != null) { input.MergeAttribute("id", ControlContextValue.Name); input.MergeAttribute("name", ControlContextValue.Name); input.MergeAttribute("value", "true"); var controlValue = ControlContextValue.Value; if (controlValue != null && bool.Parse(controlValue.ToString())) { input.MergeAttribute("checked", "checked"); } } if (DisabledValue) { input.MergeAttribute("disabled", "disabled"); } ApplyCss(input); ApplyAttributes(input); ////input.MergeAttributes(helper.HtmlHelper.GetUnobtrusiveValidationAttributes(context.ExpressionText, context.Metadata)); input.WriteFullTag(writer); writer.Write(" "); // writing space to separate text from checkbox itself writer.Write(context.HtmlEncode(TextValue)); lbl.WriteEndTag(writer); if (div != null) { div.WriteEndTag(writer); } }
protected override void WriteSelf(System.IO.TextWriter writer, IBootstrapContext context) { var formGroup = context.PeekNearest<FormGroup>(); if (formGroup != null && ControlContextValue == null) { ControlContextValue = formGroup.ControlContextValue; } ITagBuilder div = null; if (!InlineValue) { div = context.CreateTagBuilder("div"); div.AddCssClass("checkbox"); div.WriteStartTag(writer); } var lbl = context.CreateTagBuilder("label"); if (InlineValue) { lbl.AddCssClass("checkbox-inline"); } lbl.WriteStartTag(writer); var input = context.CreateTagBuilder("input"); input.MergeAttribute("type", "checkbox"); if (ControlContextValue != null) { input.MergeAttribute("id", ControlContextValue.Name); input.MergeAttribute("name", ControlContextValue.Name); input.MergeAttribute("value", "true"); var controlValue = ControlContextValue.Value; if (controlValue != null && bool.Parse(controlValue.ToString())) { input.MergeAttribute("checked", "checked"); } } if (DisabledValue) { input.MergeAttribute("disabled", "disabled"); } ApplyCss(input); ApplyAttributes(input); ////input.MergeAttributes(helper.HtmlHelper.GetUnobtrusiveValidationAttributes(context.ExpressionText, context.Metadata)); input.WriteFullTag(writer); writer.Write(" "); // writing space to separate text from checkbox itself writer.Write(context.HtmlEncode(TextValue)); lbl.WriteEndTag(writer); if (div != null) { div.WriteEndTag(writer); } }