private static DivTag BuildTestDiv(Stack <int> indexes, int depth) { var div = new DivTag(); div.AddClass("depth-level"); var classToAdd = "depth-level-{0}".ToFormat(depth); div.AddClass(classToAdd); indexes.Each(x => { classToAdd += "-" + x; div.AddClass(classToAdd); }); var span = new HtmlTag("span"); span.Text("{0}Div at depth {1} index {2}".ToFormat(new String('-', depth), depth, indexes.Peek())); div.Children.Add(span); if (depth < 3) { for (var i = 0; i < 3; i++) { indexes.Push(i); var childDiv = BuildTestDiv(indexes, depth + 1); indexes.Pop(); div.Children.Add(childDiv); } } return(div); }
public static HtmlTag ValidationText <T>(this HtmlHelpers <T> html, string name) { return(HtmlTag.Empty()); var result = html.RenderContext.Context.ModelValidationResult; if (result.IsValid) { return(HtmlTag.Empty()); } if (!result.Errors.ContainsKey(name)) { return(HtmlTag.Empty()); } var error = result.Errors[name]; if (error.Count == 0) { return(HtmlTag.Empty()); } var tag = new DivTag(); tag.Text(error[0]); return(tag.AddClass("error")); }
protected virtual void WrapFieldWithDiv(IDefinedConventions editor) { editor. If(WhenToWrapFields) .Modify((tag, model) => { var wrapper = new DivTag(); if (tag is MvcCheckboxElement) { wrapper.AddClass("checkbox"); } else { wrapper.AddClass("form-group"); } if (model.ValidationFailed) { wrapper.AddClass("has-error"); } return(tag.WrapWith(wrapper)); }); }
protected override HtmlTag CreateTag() { var label = new HtmlTag("label").Attr("for", _id); if (_mandatory && !_control.HandlesMandatoryInline()) { label.Append(NewMandatory()); } label.Append(new HtmlTag("span").Text(_labelText)); var controlTag = _control.GenerateTag(_mandatory); var inputWrapper = new DivTag().AddClasses("input-wrapper").Append(controlTag); var formGroup = new DivTag() .Id(_id + "_FormGroup") .AddClasses("form-group") .Append(label) .Append(inputWrapper); if (!string.IsNullOrWhiteSpace(_hintHtml)) { var hint = new HtmlTag("p").AddClasses("help-block").AppendHtml(_hintHtml); label.Append(hint); } if (_controlWidth.HasValue && _controlWidth.Value != ControlWidth.Max) { inputWrapper.AddClass("control-width-" + _controlWidth.Value.ToString().ToLower()); } if (_initiallyHidden) { formGroup.AddClasses("initially-hidden"); } if (!_visible) { formGroup.Style("display", "none"); } if (!string.IsNullOrWhiteSpace(_ajaxOnChangeAction)) { formGroup.Attr("data-ajax-change", UrlHelper.Content(_ajaxOnChangeAction)); } return(formGroup); }
protected override HtmlTag CreateTag(bool inlineMandatory = false) { var container = new DivTag().AddClasses("confirm-check-box"); if (_emphasise) { container.AddClass("emphasise"); } var modelValue = RenderValue(); var input = new HtmlTag("input").Attr("type", "checkbox").Name(ControlContext.Name).Value("True"); if (_disabled) { input.Attr("disabled", "disabled"); } if (modelValue != null && modelValue.ToLower() == "true") { input.Attr("checked", "checked"); } var labelText = _labelText ?? ControlContext.Metadata.DisplayName ?? ControlContext.Metadata.PropertyName; var text = new HtmlTag("span"); if (inlineMandatory) { text.Append(NewMandatory()); } text.Append(new HtmlTag("span").Text(labelText)); var label = new HtmlTag("label").Append(input).Append(text); return(container.Append(label)); }
protected static HtmlTag ColumnSetRender(ColumnSet columnSet, RenderContext context) { var uiColumnSet = new DivTag() .AddClass($"ac-{columnSet.Type.Replace(".", "").ToLower()}") .Style("overflow", "hidden") .Style("display", "flex"); if (context.Config.SupportsInteractivity && columnSet.SelectAction != null) { uiColumnSet.AddClass("ac-tap"); } var max = Math.Max(1.0, columnSet.Columns.Select(col => { if (col.Width != null && double.TryParse(col.Width, out double widthVal)) { return(widthVal); } #pragma warning disable CS0618 // Type or member is obsolete if (double.TryParse(col.Size ?? "0", out double val)) #pragma warning restore CS0618 // Type or member is obsolete { return(val); } return(0); }).Sum()); foreach (var column in columnSet.Columns) { var uiColumn = context.Render(column); // Add horizontal Seperator if (uiColumnSet.Children.Any() && (column.Separator || column.Spacing != Spacing.None)) { SeparatorConfig sep = context.Config.Separator; int spacing = context.Config.GetSpacing(column.Spacing); int lineThickness = column.Separator ? sep.LineThickness : 0; if (sep != null) { uiColumnSet.Children.Add(new DivTag() .AddClass($"ac-columnseparator") .Style("flex", "0 0 auto") .Style("padding-left", $"{spacing}px") .Style("margin-left", $"{spacing}px") .Style("border-left-color", $"{context.GetRGBColor(sep.LineColor)}") .Style("border-left-width", $"{lineThickness}px") .Style("border-left-style", $"solid")); } } // do some sizing magic var width = column.Width?.ToLower(); if (string.IsNullOrEmpty(width)) #pragma warning disable CS0618 // Type or member is obsolete { width = column.Size?.ToLower(); } #pragma warning restore CS0618 // Type or member is obsolete if (width == null || width == ColumnWidth.Stretch.ToLower()) { uiColumn = uiColumn.Style("flex", "1 1 auto"); } else if (width == ColumnWidth.Auto.ToLower()) { uiColumn = uiColumn.Style("flex", "0 1 auto"); } else { double val; if (double.TryParse(width, out val)) { var percent = Convert.ToInt32(100 * (val / max)); uiColumn = uiColumn.Style("flex", $"1 1 {percent}%"); } else { uiColumn = uiColumn.Style("flex", "0 0 auto"); } } uiColumnSet.Children.Add(uiColumn); } return(uiColumnSet); }