daveaglick / FluentBootstrap

Provides extensions, helper classes, model binding, and other goodies to help you use the Bootstrap CSS framework from .NET code.
http://www.fluentbootstrap.com
MIT License
200 stars 76 forks source link

Additional label tag from FormControl #72

Closed fairking closed 7 years ago

fairking commented 7 years ago

Can the Label not be generated when it's empty?

@(Html.Bootstrap()
    .FormGroup()
    .AddChild(Html.Bootstrap().ControlLabel(x => x.H_TestDisplayStringValue).SetMd(4))
    .AddChild(FluentBootstrap.FormExtensions.AddStaticClass(Html.Bootstrap().FormControl()).SetMd(7)
        .AddContent(Html.DisplayFor(x => x.H_TestDisplayStringValue))
    )
    .AddChild(Html.Bootstrap().BadgeTooltip("Test Display").SetPullRight())
)

Result: 20161116_1750

Also I can not understand why SetMd renders additional div. There are lot of inconvenience during coding by Fluent Bootstrap. I've done some tests around and found it's not ready to be used in production. Some things just don't allow me to do what I exactly want.

Thanks.

daveaglick commented 7 years ago

Sorry you're having problems. It's very challenging to wrap a framework as big as Bootstrap successfully without any edge cases. As you've discovered there are certainly still some bugs, mostly related to integrating with the MVC view model and HtmlHelper class. That said, I (and many others) have been using it in production scenarios for quite a while. I guess it all depends on the demands of your production environment and if you'll tend to encounter these edge cases (or care to work through them).

I certainly welcome any help you can give. As with most OSS, this is a volunteer project. If you run across bugs or output that doesn't match your expectations, PRs are always welcome :smile:

fairking commented 7 years ago

Hi @daveaglick. Thanks a lot for your help. I'm trying to create some kind of helper, but I'm using HtmlHelper and TagBuilder at the moment: 20161130

As you can see most of form groups is just one line.

The helper looks like that:

public class FormGroupExtensionConfig<TModel, TValue> : BaseExtensionConfig<TModel, TValue>
    {
        public FormGroupExtensionConfig(HtmlHelper<TModel> helper, Expression<Func<TModel, TValue>> expression)
            : base(helper, expression)
        {
            RequiredLabel = true;
        }

        protected bool RequiredLabel { get; protected set; }
        protected bool Tooltip { get; protected set; }
        protected string TooltipText { get; protected set; }
...

        public FormGroupExtensionConfig<TModel, TValue> WithNoRequiredLabel(bool requiredLabel = false)
        {
            RequiredLabel = requiredLabel;
            return this;
        }

        public FormGroupExtensionConfig<TModel, TValue> WithTooltip(string tooltip = "")
        {
            Tooltip = true;
            TooltipText = tooltip;
            return this;
        }
...
        public override string ToHtmlString()
        {
            var requiredLabelCss = RequiredLabel && Expression.IsRequired() ? " required" : "";
            var horizontalLabelCss = Horizontal ? " col-md-4" : "";
            var horizontalWrapperCss = Horizontal ? " col-md-7" : "";
            var displayWrapperCss = Display ? " form-control-static" : "";
            var controlCss = NoFormControlCss ? "" : " form-control";
            var groupCss = Fixed ? "group-fixed" : "";

            // FormGroup
            var formGroup = new TagBuilder("div")
                .AddAttribute("id", Helper.IdFor(Expression).ToString() + "_FormGroup")
                .AddCss("form-group")
                .AddCss(groupCss);

            // Label
            if (!NoLabel)
            {
                formGroup
                    .AddChild(
                        Label != null 
                        ? Helper.LabelFor(Expression, Label, new { @class = "control-label" + requiredLabelCss + horizontalLabelCss })
                        : Helper.LabelFor(Expression, new { @class = "control-label" + requiredLabelCss + horizontalLabelCss })
                        );
            }
            else if (Horizontal)
            {
                formGroup
                    .AddChild(new TagBuilder("div").AddCss(horizontalLabelCss), TagRenderMode.Normal);
            }
...

I hope your framework will grow and expand in the best way. I'm rushing with some my project so I don't have too much time to understand and improve fluentbootstrap. - I've got hungry kids and huge taxes at the moment. :-)

Cheers.