protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context) { var form = context.PeekNearest <IFormContext>(); var formGroup = context.PeekNearest <FormGroup>(); if (form != null && form.TypeValue == FormType.Inline) { return(string.Empty); } ITagBuilder tb = null; ITagBuilder tb2 = null; if (form != null && form.TypeValue == FormType.Horizontal) { tb = context.CreateTagBuilder("div"); tb.AddCssClass(form.ControlsWidthValue.ToCssClass()); if (WithoutLabelValue) { tb.AddCssClass(form.ControlsWidthValue.Invert().ToOffsetCssClass()); } ApplyCss(tb); ApplyAttributes(tb); tb.WriteStartTag(writer); } if (formGroup != null && formGroup.WithSizedControlValue) { tb2 = context.CreateTagBuilder("div"); tb2.AddCssClass("row"); tb2.WriteStartTag(writer); } if (tb != null && tb2 != null) { return(tb2.GetEndTag() + tb.GetEndTag()); } if (tb2 != null) { return(tb2.GetEndTag()); } if (tb != null) { return(tb.GetEndTag()); } return(string.Empty); }
private string WriteControlsStart(System.IO.TextWriter writer, IForm formContext, bool noLabel) { if (formContext != null && formContext.Type == FormType.Inline) { return(string.Empty); } ITagBuilder tb = null; ITagBuilder tb2 = null; if (formContext != null && formContext.Type == FormType.Horizontal) { tb = Helper.CreateTagBuilder("div"); tb.AddCssClass(formContext.ControlsWidth.ToCssClass()); if (noLabel) { tb.AddCssClass(formContext.ControlsWidth.Invert().ToOffsetCssClass()); } ApplyCss(tb); ApplyAttributes(tb); tb.WriteStartTag(writer); } if (WithSizedControl) { tb2 = Helper.CreateTagBuilder("div"); tb2.AddCssClass("row"); tb2.WriteStartTag(writer); } if (tb != null && tb2 != null) { return(tb2.GetEndTag() + tb.GetEndTag()); } if (tb2 != null) { return(tb2.GetEndTag()); } if (tb != null) { return(tb.GetEndTag()); } return(string.Empty); }
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 input = context.CreateTagBuilder("input"); input.AddCssClass("form-control"); var actualType = TypeValue; if (actualType != InputType.File && ControlContextValue != null) { input.MergeAttribute("id", ControlContextValue.Name); input.MergeAttribute("name", ControlContextValue.Name); if (ControlContextValue.IsRequired) { input.MergeAttribute("required", "required"); } var value = ControlContextValue.Value; if (value != null) { var valueString = value.ToString(); if (TypeValue == InputType.Date || TypeValue == InputType.Datetime || TypeValue == InputType.DatetimeLocal || TypeValue == InputType.Time) { var valueDateTime = value as DateTime?; var valueDateTimeOffset = value as DateTimeOffset?; var valueTimeSpan = value as TimeSpan?; if (valueDateTimeOffset.HasValue) { valueDateTime = valueDateTimeOffset.Value.DateTime; } if (valueDateTime.HasValue) { valueTimeSpan = valueDateTime.Value.TimeOfDay; } var asHtml5 = (DateInputMode == BootstrapMvc.DateInputMode.Html5); if (!asHtml5) { actualType = InputType.Text; } switch (TypeValue) { case InputType.Date: if (valueDateTime.HasValue) { valueString = asHtml5 ? valueDateTime.Value.ToString("yyyy-MM-dd") : valueDateTime.Value.ToString("d"); } break; case InputType.DatetimeLocal: if (valueDateTime.HasValue) { valueString = asHtml5 ? valueDateTime.Value.ToString("o") : valueDateTime.Value.ToString(); } break; case InputType.Datetime: if (valueDateTime.HasValue) { valueString = asHtml5 ? valueDateTimeOffset.Value.ToString("o") : valueDateTimeOffset.Value.ToString(); } break; case InputType.Time: if (valueDateTime.HasValue) { valueString = valueTimeSpan.ToString(); } break; } } input.MergeAttribute("value", valueString); } } if (actualType != InputType.Text) { input.MergeAttribute("type", actualType.ToType()); } if (DisabledValue) { input.MergeAttribute("disabled", "disabled"); } ApplyCss(input); ApplyAttributes(input); ////input.MergeAttributes(helper.HtmlHelper.GetUnobtrusiveValidationAttributes(context.ExpressionText, context.Metadata)); writer.Write(input.GetFullTag()); if (div != null) { writer.Write(div.GetEndTag()); } }
protected override void WriteSelfStart(System.IO.TextWriter writer) { var formContext = GetNearestParent <IForm>(); var formGroupContext = GetNearestParent <FormGroup>(); var controlContext = GetNearestParent <IControlContext>(); ITagBuilder div = null; if (!Size.IsEmpty()) { // Inline forms does not support sized controls (we need 'some other' sizing rules?) if (formContext != null && formContext.Type != FormType.Inline) { if (formGroupContext != null && formGroupContext.WithSizedControl) { div = Helper.CreateTagBuilder("div"); div.AddCssClass(Size.ToCssClass()); div.WriteStartTag(writer); } else { throw new InvalidOperationException("Size not allowed - call WithSizedControls() on FormGroup."); } } } object value = null; var tb = Helper.CreateTagBuilder("select"); tb.AddCssClass("form-control"); if (controlContext != null) { tb.MergeAttribute("id", controlContext.FieldName, true); tb.MergeAttribute("name", controlContext.FieldName, true); if (controlContext.IsRequired) { tb.MergeAttribute("required", "required", true); } value = controlContext.FieldValue; } if (Disabled) { tb.MergeAttribute("disabled", "disabled", true); } ApplyCss(tb); ApplyAttributes(tb); tb.WriteStartTag(writer); if (Items != null) { foreach (var item in Items) { item.Parent = this; item.WriteTo(writer); } } endTag = tb.GetEndTag() + (div == null ? string.Empty : div.GetEndTag()); }
protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context) { var form = context.PeekNearest <IFormContext>(); var formGroup = context.PeekNearest <FormGroup>(); if (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."); } } } object value = null; var tb = context.CreateTagBuilder("select"); tb.AddCssClass("form-control"); if (ControlContextValue != null) { tb.MergeAttribute("id", ControlContextValue.Name); tb.MergeAttribute("name", ControlContextValue.Name); if (ControlContextValue.IsRequired) { tb.MergeAttribute("required", "required"); } value = ControlContextValue.Value; } if (DisabledValue) { tb.MergeAttribute("disabled", "disabled"); } ApplyCss(tb); ApplyAttributes(tb); writer.Write(tb.GetStartTag()); context.Push(this); if (ItemsValue != null) { foreach (var item in ItemsValue) { item.WriteTo(writer, context); } } endTag = tb.GetEndTag() + (div == null ? string.Empty : div.GetEndTag()); }
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("radio"); writer.Write(div.GetStartTag()); } var lbl = context.CreateTagBuilder("label"); if (InlineValue) { lbl.AddCssClass("radio-inline"); } writer.Write(lbl.GetStartTag()); var input = context.CreateTagBuilder("input"); input.MergeAttribute("type", "radio"); if (ControlContextValue != null) { input.MergeAttribute("id", ControlContextValue.Name); input.MergeAttribute("name", ControlContextValue.Name); input.MergeAttribute("value", ValueValue?.ToString()); var controlValue = ControlContextValue.Value; if (controlValue != null && ValueValue != null && ValueValue.ToString().Equals(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)); writer.Write(input.GetFullTag()); writer.Write(" "); // writing space to separate text from radio itself writer.Write(context.HtmlEncode(TextValue)); writer.Write(lbl.GetEndTag()); if (div != null) { writer.Write(div.GetEndTag()); } }