/// <inheritdoc />
        public IHtmlContent GetLabelHtml(IReadonlyFieldConfiguration fieldConfiguration)
        {
            fieldConfiguration = fieldConfiguration ?? new FieldConfiguration();

            string @for;

            if (fieldConfiguration.HtmlAttributes.ContainsKey("id"))
            {
                @for = fieldConfiguration.HtmlAttributes["id"].ToString();
            }
            else
            {
                @for = HtmlHelper.GetFullHtmlFieldName(FieldProperty);
            }

            var labelText = fieldConfiguration.LabelText
                            ?? GetFieldDisplayName().ToHtml();

            if (!fieldConfiguration.HasLabelElement)
            {
                return(labelText);
            }

            var labelAttrs = new HtmlAttributes();

            if (!string.IsNullOrEmpty(fieldConfiguration.LabelClasses))
            {
                labelAttrs.AddClass(fieldConfiguration.LabelClasses);
            }

            return(HtmlCreator.BuildLabel(@for, labelText, labelAttrs));
        }
Пример #2
0
        private IHtmlString GetSingleCheckboxHtml(IReadonlyFieldConfiguration fieldConfiguration)
        {
            var attrs = new HtmlAttributes(fieldConfiguration.HtmlAttributes);

            AdjustHtmlForModelState(attrs, FieldGenerator);
            var fieldhtml = HtmlCreator.BuildSingleCheckbox(GetFieldName(FieldGenerator), GetValue() ?? false, attrs);

            if (fieldConfiguration.HasInlineLabel)
            {
                if (fieldConfiguration.ShouldInlineLabelWrapElement)
                {
                    var inlineLabelText = fieldConfiguration.InlineLabelText;

                    var content = fieldhtml.ToHtmlString() + " " + (inlineLabelText != null ? inlineLabelText.ToHtmlString() : FieldGenerator.GetFieldDisplayName());

                    return(HtmlCreator.BuildLabel(null, new HtmlString(content), null));
                }
                else
                {
                    return(new HtmlString(string.Format("{0} {1}", fieldhtml, HtmlCreator.BuildLabel(
                                                            GetFieldName(FieldGenerator),
                                                            fieldConfiguration.InlineLabelText ?? FieldGenerator.GetFieldDisplayName().ToHtml(),
                                                            null
                                                            ))));
                }
            }
            else
            {
                return(fieldhtml);
            }
        }
Пример #3
0
        private IHtmlString GetSingleCheckboxHtml(IReadonlyFieldConfiguration fieldConfiguration)
        {
            var attrs = new HtmlAttributes(fieldConfiguration.HtmlAttributes);

            AdjustHtmlForModelState(attrs, FieldGenerator);
            var fieldhtml = HtmlCreator.BuildSingleCheckbox(GetFieldName(FieldGenerator), GetValue() ?? false, attrs);
            var labelHtml = HtmlCreator.BuildLabel(
                GetFieldName(FieldGenerator),
                fieldConfiguration.InlineLabelText ?? FieldGenerator.GetFieldDisplayName().ToHtml(),
                null
                );

            return(new HtmlString(string.Format("{0} {1}", fieldhtml, labelHtml)));
        }
Пример #4
0
        private Nancy.ViewEngines.Razor.IHtmlString GetSingleCheckboxHtml()
        {
            var attrs = new HtmlAttributes(FieldConfiguration.HtmlAttributes);

            AdjustHtmlForModelState(attrs);
            var fieldhtml = HtmlCreator.BuildSingleCheckbox(GetFieldName(), GetValue() ?? false, attrs);
            var labelHtml = HtmlCreator.BuildLabel(
                GetFieldName(),
                FieldConfiguration.InlineLabelText ?? new NonEncodedHtmlString(FieldGenerator.GetFieldDisplayName()),
                null
                );

            return(new NonEncodedHtmlString(string.Format("{0} {1}", fieldhtml, labelHtml)));
        }
Пример #5
0
        private IHtmlContent GetSingleCheckboxHtml(IReadonlyFieldConfiguration fieldConfiguration)
        {
            var attrs = new HtmlAttributes(fieldConfiguration.HtmlAttributes);

            AdjustHtmlForModelState(attrs);
            var fieldHtml = HtmlCreator.BuildSingleCheckbox(GetFieldName(), GetValue() ?? false, attrs);

            if (fieldConfiguration.HasInlineLabel)
            {
                if (fieldConfiguration.ShouldInlineLabelWrapElement)
                {
                    var inlineLabelText = fieldConfiguration.InlineLabelText;

                    var contentBuilder = new HtmlContentBuilder();
                    contentBuilder.AppendHtml(fieldHtml);
                    contentBuilder.Append(" ");
                    if (inlineLabelText != null)
                    {
                        contentBuilder.AppendHtml(inlineLabelText);
                    }
                    else
                    {
                        contentBuilder.Append(FieldGenerator.GetFieldDisplayName());
                    }

                    return(HtmlCreator.BuildLabel(null, contentBuilder, null));
                }
                else
                {
                    return(new HtmlContentBuilder()
                           .AppendHtml(fieldHtml)
                           .Append(" ")
                           .AppendHtml(HtmlCreator.BuildLabel(GetFieldName(), fieldConfiguration.InlineLabelText ?? FieldGenerator.GetFieldDisplayName().ToHtml(), null)));
                }
            }
            else
            {
                return(fieldHtml);
            }
        }
Пример #6
0
        public Nancy.ViewEngines.Razor.IHtmlString GetLabelHtml(IReadonlyFieldConfiguration fieldConfiguration)
        {
            string @for;

            if (fieldConfiguration != null && fieldConfiguration.HtmlAttributes.ContainsKey("id"))
            {
                @for = fieldConfiguration.HtmlAttributes["id"].ToString();
            }
            else
            {
                @for = HtmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(
                    ExpressionHelper.GetExpressionText(FieldProperty));
            }

            var labelText = (fieldConfiguration == null ? null : fieldConfiguration.LabelText)
                            ?? new NonEncodedHtmlString(GetFieldDisplayName());

            if (fieldConfiguration != null && !fieldConfiguration.HasLabel)
            {
                return(labelText);
            }

            return(HtmlCreator.BuildLabel(@for, labelText, null));
        }