private protected IHtmlContent GenerateErrorMessage(FormGroupBuilder builder)
        {
            var visuallyHiddenText = builder.ErrorMessage?.visuallyHiddenText;
            var content            = builder.ErrorMessage?.content;
            var attributes         = builder.ErrorMessage?.attributes;

            if (content == null && AspFor != null && IgnoreModelStateErrors != true)
            {
                var validationMessage = Generator.GetValidationMessage(ViewContext, AspFor.ModelExplorer, AspFor.Name);

                if (validationMessage != null)
                {
                    content = new HtmlString(validationMessage);
                }
            }

            if (content != null)
            {
                var errorId = ResolvedId + "-error";
                AppendToDescribedBy(errorId);
                return(Generator.GenerateErrorMessage(visuallyHiddenText, errorId, content, attributes));
            }
            else
            {
                return(null);
            }
        }
        protected override TagBuilder GenerateElement(
            TagHelperContext context,
            FormGroupBuilder builder,
            FormGroupElementContext elementContext)
        {
            var textAreaBuilder = (TextAreaBuilder)builder;

            if (textAreaBuilder.Content == null && AspFor == null)
            {
                throw new InvalidOperationException(
                          $"Content must be specified when the '{AspForAttributeName}' attribute is not specified.");
            }

            var resolvedContent = textAreaBuilder.Content ??
                                  new HtmlString(Generator.GetModelValue(ViewContext, AspFor.ModelExplorer, AspFor.Name));

            return(Generator.GenerateTextArea(
                       elementContext.HaveError,
                       ResolvedId,
                       ResolvedName,
                       Rows,
                       DescribedBy,
                       Autocomplete,
                       IsDisabled,
                       resolvedContent,
                       Attributes));
        }
 protected virtual TagBuilder GenerateElement(
     TagHelperContext context,
     FormGroupBuilder builder,
     FormGroupElementContext elementContext)
 {
     // For deriving classes to implement when required
     throw new NotImplementedException();
 }
Exemplo n.º 4
0
 protected override TagBuilder GenerateElement(TagHelperContext context, FormGroupBuilder builder, FormGroupElementContext elementContext)
 {
     return(Generator.GenerateFileUpload(
                elementContext.HaveError,
                ResolvedId,
                ResolvedName,
                DescribedBy,
                Attributes));
 }
Exemplo n.º 5
0
        protected override TagBuilder GenerateElement(
            TagHelperContext context,
            FormGroupBuilder builder,
            FormGroupElementContext elementContext)
        {
            var textArea = base.GenerateElement(context, builder, elementContext);

            textArea.AddCssClass("govuk-js-character-count");
            return(textArea);
        }
        private protected virtual IHtmlContent GenerateLabel(FormGroupBuilder builder)
        {
            var isPageHeading = builder.Label?.isPageHeading ?? false;
            var content       = builder.Label?.content;
            var attributes    = builder.Label?.attributes;

            var resolvedContent = content ??
                                  new HtmlString(Generator.GetDisplayName(ViewContext, AspFor.ModelExplorer, AspFor.Name));

            return(Generator.GenerateLabel(ResolvedId, isPageHeading, resolvedContent, attributes));
        }
 private protected virtual TagBuilder GenerateHint(FormGroupBuilder builder)
 {
     if (builder.Hint != null)
     {
         var hintId = ResolvedId + "-hint";
         AppendToDescribedBy(hintId);
         return(Generator.GenerateHint(hintId, builder.Hint.Value.content, builder.Hint.Value.attributes));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 8
0
        protected override TagBuilder GenerateElement(
            TagHelperContext context,
            FormGroupBuilder builder,
            FormGroupElementContext elementContext)
        {
            var selectContext = (SelectContext)context.Items[typeof(SelectContext)];

            return(Generator.GenerateSelect(
                       elementContext.HaveError,
                       ResolvedId,
                       ResolvedName,
                       DescribedBy,
                       Disabled,
                       selectContext.Items,
                       FormGroupAttributes));
        }
        protected override TagBuilder GenerateContent(TagHelperContext context, FormGroupBuilder builder)
        {
            var checkboxesContext = (CheckboxesContext)context.Items[typeof(CheckboxesContext)];

            var contentBuilder = new HtmlContentBuilder();

            var hint = GenerateHint(builder);

            if (hint != null)
            {
                contentBuilder.AppendHtml(hint);
            }

            var errorMessage = GenerateErrorMessage(builder);

            if (errorMessage != null)
            {
                contentBuilder.AppendHtml(errorMessage);
            }

            var haveError = errorMessage != null;

            var tagBuilder = Generator.GenerateCheckboxes(
                ResolvedName,
                checkboxesContext.IsConditional,
                DescribedBy,
                CheckboxesAttributes,
                checkboxesContext.Items);

            contentBuilder.AppendHtml(tagBuilder);

            IHtmlContent content = contentBuilder;

            if (checkboxesContext.Fieldset != null)
            {
                content = Generator.GenerateFieldset(
                    DescribedBy,
                    checkboxesContext.Fieldset.IsPageHeading,
                    role: null,
                    legendContent: checkboxesContext.Fieldset.LegendContent,
                    legendAttributes: checkboxesContext.Fieldset.LegendAttributes,
                    content: content,
                    attributes: checkboxesContext.Fieldset.Attributes);
            }

            return(Generator.GenerateFormGroup(haveError, content, FormGroupAttributes));
        }
        protected virtual TagBuilder GenerateContent(TagHelperContext context, FormGroupBuilder builder)
        {
            // We need some content for the label; if AspFor is null then label content must have been specified
            if (AspFor == null && (!builder.Label.HasValue || builder.Label.Value.content == null))
            {
                throw new InvalidOperationException(
                          $"Label content must be specified when the '{AspForAttributeName}' attribute is not specified.");
            }

            var contentBuilder = new HtmlContentBuilder();

            var label = GenerateLabel(builder);

            contentBuilder.AppendHtml(label);

            var hint = GenerateHint(builder);

            if (hint != null)
            {
                contentBuilder.AppendHtml(hint);
            }

            var errorMessage = GenerateErrorMessage(builder);

            if (errorMessage != null)
            {
                contentBuilder.AppendHtml(errorMessage);
            }

            var haveError = errorMessage != null;

            var elementCtx = new FormGroupElementContext(haveError);
            var element    = GenerateElement(context, builder, elementCtx);

            contentBuilder.AppendHtml(element);

            return(Generator.GenerateFormGroup(haveError, contentBuilder, FormGroupAttributes));
        }
Exemplo n.º 11
0
        protected override TagBuilder GenerateContent(TagHelperContext context, FormGroupBuilder builder)
        {
            var generated = base.GenerateContent(context, builder);

            return(Generator.GenerateCharacterCount(ResolvedId, MaxLength, MaxWords, Threshold, generated));
        }