protected override async Task BootstrapProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "div";
            output.AddCssClass("input-group");
            if ((Size ?? SimpleSize.Default) != SimpleSize.Default)
            {
                output.AddCssClass("input-group-" + Size.Value.GetDescription());
            }
            if (!string.IsNullOrEmpty(PreAddonText))
            {
                output.PreContent.SetHtmlContent(AddonTagHelper.GenerateAddon(PreAddonText));
            }
            if (!string.IsNullOrEmpty(PostAddonText))
            {
                output.PostContent.SetHtmlContent(AddonTagHelper.GenerateAddon(PostAddonText));
            }
            await output.GetChildContentAsync();

            var preElementContent = output.PreElement.GetContent();

            output.PreElement.Clear();
            if (FormGroupContext != null)
            {
                FormGroupContext.WrapInDivForHorizontalForm(output, context.GetContextItem <FormGroupTagHelper>()?.HasLabel ?? false);
            }
            else if (FormContext != null)
            {
                FormContext.WrapInDivForHorizontalForm(output, context.GetContextItem <FormGroupTagHelper>()?.HasLabel ?? false);
            }
            output.PreElement.PrependHtml(preElementContent);
            if (!string.IsNullOrEmpty(HelpContent))
            {
                output.PostElement.PrependHtml(HelpBlockTagHelper.GenerateHelpBlock(HelpContent));
            }
        }
Пример #2
0
 private void ProcessCheckControl(TagHelperContext context, TagHelperOutput output)
 {
     if (this.InputGroupContext != null)
     {
         output.PreElement.Append(this.Label);
         if (!context.HasContextItem <AddonTagHelper>())
         {
             output.PreElement.AppendHtml("<span class=\"input-group-addon\">");
             output.PostElement.PrependHtml("</span>");
         }
     }
     else if (this.IsInLabel)
     {
         output.PostElement.Append(this.Label);
     }
     else
     {
         LabelTagHelper.WrapInLabel(output, this.Label, null, this.FormContext);
     }
     if (!string.IsNullOrEmpty(HelpText))
     {
         if (InputGroupContext != null)
         {
             InputGroupContext.Output.PostElement.AppendHtml(HelpBlockTagHelper.GenerateHelpBlock(HelpText));
         }
         else
         {
             output.PostElement.AppendHtml(HelpBlockTagHelper.GenerateHelpBlock(HelpText));
         }
     }
     if (!IsInLabel)
     {
         output.PreElement.PrependHtml(
             FormContext?.Inline ?? false
                                           ? $"<div class=\"{Type.ToLower()}-inline\">"
                                           : $"<div class=\"{Type.ToLower()}\">");
         output.PostElement.AppendHtml("</div>");
         if (FormGroupContext != null)
         {
             FormGroupContext.WrapInDivForHorizontalForm(output, false);
         }
         else if (FormContext != null)
         {
             FormContext.WrapInDivForHorizontalForm(output, false);
         }
     }
 }
Пример #3
0
 protected override void BootstrapProcess(TagHelperContext context, TagHelperOutput output)
 {
     output.AddCssClass("form-control");
     if (FormGroupContext != null)
     {
         FormGroupContext.WrapInDivForHorizontalForm(output, !string.IsNullOrEmpty(Label));
     }
     else if (FormContext != null)
     {
         FormContext.WrapInDivForHorizontalForm(output, !string.IsNullOrEmpty(Label));
     }
     if (!string.IsNullOrEmpty(Label))
     {
         output.PreElement.Prepend(LabelTagHelper.GenerateLabel(Label, FormContext));
     }
     if (!string.IsNullOrEmpty(HelpText))
     {
         output.PostElement.PrependHtml(HelpBlockTagHelper.GenerateHelpBlock(HelpText));
     }
     if (Size != null && Size != BootstrapTagHelpers.Size.Default)
     {
         output.AddCssClass("input-" + Size.Value.GetDescription());
     }
 }
Пример #4
0
        private void ProcessNonCheckControl(TagHelperOutput output)
        {
            output.AddCssClass("form-control");
            if (!string.IsNullOrEmpty(PostAddonText) || !string.IsNullOrEmpty(PreAddonText))
            {
                if ((Size ?? BootstrapTagHelpers.Size.Default) != BootstrapTagHelpers.Size.Default)
                {
                    var size = Size == BootstrapTagHelpers.Size.Large
                                   ? BootstrapTagHelpers.Size.Large
                                   : BootstrapTagHelpers.Size.Small;
                    output.PreElement.PrependHtml($"<div class=\"input-group input-group-{size.GetDescription()}\">");
                }
                else
                {
                    output.PreElement.PrependHtml("<div class=\"input-group\">");
                }
                if (!string.IsNullOrEmpty(PreAddonText))
                {
                    output.PreElement.AppendHtml(AddonTagHelper.GenerateAddon(PreAddonText));
                }
                if (!string.IsNullOrEmpty(PostAddonText))
                {
                    output.PostElement.AppendHtml(AddonTagHelper.GenerateAddon(PostAddonText));
                }
                output.PostElement.AppendHtml("</div>");
            }
            else if (Size != null && Size != BootstrapTagHelpers.Size.Default)
            {
                output.AddCssClass("input-" + Size.Value.GetDescription());
            }
            if (!string.IsNullOrEmpty(HelpText))
            {
                if (InputGroupContext != null)
                {
                    InputGroupContext.Output.PostElement.PrependHtml(HelpBlockTagHelper.GenerateHelpBlock(HelpText));
                }
                else
                {
                    output.PostElement.AppendHtml(HelpBlockTagHelper.GenerateHelpBlock(HelpText));
                }
            }
            if (InputGroupContext == null)
            {
                if (FormGroupContext != null)
                {
                    FormGroupContext.WrapInDivForHorizontalForm(output, !string.IsNullOrEmpty(Label));
                }
                else if (FormContext != null)
                {
                    FormContext.WrapInDivForHorizontalForm(output, !string.IsNullOrEmpty(Label));
                }
            }
            if (!string.IsNullOrEmpty(Label))
            {
                if (InputGroupContext == null)
                {
                    output.PreElement.Prepend(LabelTagHelper.GenerateLabel(Label, Id, FormContext));
                }
                else
                {
                    InputGroupContext.Output.PreElement.Prepend(
                        LabelTagHelper.GenerateLabel(
                            Label, Id,
                            FormContext));
                }
            }
            if (FormGroupContext != null && FormGroupContext.HasFeedback &&
                FormGroupContext.ValidationContext != null)
            {
                string cssClass;
                string srText;
                switch (FormGroupContext.ValidationContext.Value)
                {
                case ValidationContext.Success:
                    cssClass = "ok";
                    srText   = Ressources.ValidationSuccess;
                    break;

                case ValidationContext.Warning:
                    cssClass = "warning-sign";
                    srText   = Ressources.ValidationWarning;
                    break;

                case ValidationContext.Error:
                    cssClass = "remove";
                    srText   = Ressources.ValidationError;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                output.PostElement.PrependHtml(
                    $"<span class=\"glyphicon glyphicon-{cssClass} form-control-feedback\" aria-hidden=\"true\"></span>");
                output.PostElement.PrependHtml($"<span class=\"sr-only\">({srText})</span>");
            }
        }