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 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 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 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()); } }