Esempio n. 1
0
        /// <inheritdoc />
        public override async Task ProcessWhileAwareOfModelTypeAsync <TModel>(TagHelperContext context, TagHelperOutput output)
        {
            var helper = ViewContext.GetHtmlHelper <TModel>();

            var fieldContext = new ManualFieldContext
            {
                ModelMetadata      = ModelMetadata,
                IsValid            = IsValid,
                FieldConfiguration = context.GetFieldConfiguration()
            };

            context.Items[typeof(ManualFieldTagHelper)] = fieldContext;

            // ReSharper disable once MustUseReturnValue
            await output.GetChildContentAsync();

            if (helper.IsInChameleonFormsSection())
            {
                var s = helper.GetChameleonFormsSection();
                output.TagName = null;
                output.Content.SetHtmlContent(s.Field(fieldContext.Label, fieldContext.Element, fieldContext.Validation, fieldContext.ModelMetadata, fieldContext.IsValid ?? true, fieldContext.FieldConfiguration));
            }
            else
            {
                throw new NotSupportedException("Attempt to specify a <field> outside of a <form-section>.");
            }
        }
        /// <summary>
        /// Called when the tag helper is being processed.
        /// </summary>
        /// <param name="context">The context within which the tag helper is processed</param>
        /// <param name="output">The output from the tag helper</param>
        public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var fc = context.GetFieldConfiguration();

            if (Label != null)
            {
                fc.Label(Label);
            }

            if (LabelHtml != null)
            {
                fc.Label(LabelHtml);
            }

            if (LabelHtmlContent != null)
            {
                fc.Label(LabelHtmlContent);
            }

            if (WithoutLabelElement)
            {
                fc.WithoutLabelElement();
            }

            if (!string.IsNullOrWhiteSpace(AddLabelClass))
            {
                fc.AddLabelClass(AddLabelClass);
            }

            return(Task.CompletedTask);
        }
Esempio n. 3
0
        /// <summary>
        /// Called when the tag helper is being processed.
        /// </summary>
        /// <param name="context">The context within which the tag helper is processed</param>
        /// <param name="output">The output from the tag helper</param>
        public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var fc = context.GetFieldConfiguration();

            FluentConfig?.Invoke(fc);

            return(Task.CompletedTask);
        }
Esempio n. 4
0
        /// <inheritdoc />
        public override Task ProcessUsingModelPropertyAsync <TModel, TProperty>(TagHelperContext context, TagHelperOutput output,
                                                                                Expression <Func <TModel, TProperty> > modelProperty)
        {
            var helper = ViewContext.GetHtmlHelper <TModel>();
            var f      = helper.GetChameleonForm();

            output.TagMode = TagMode.StartTagAndEndTag;
            output.TagName = null;
            output.Content.SetHtmlContent(f.FieldElementFor(modelProperty, context.GetFieldConfiguration()));
            return(Task.CompletedTask);
        }
        /// <summary>
        /// Called when the tag helper is being processed.
        /// </summary>
        /// <param name="context">The context within which the tag helper is processed</param>
        /// <param name="output">The output from the tag helper</param>
        public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var fc = context.GetFieldConfiguration();

            if (!string.IsNullOrWhiteSpace(AddValidationClass))
            {
                fc.AddValidationClass(AddValidationClass);
            }

            return(Task.CompletedTask);
        }
Esempio n. 6
0
        /// <inheritdoc />
        public override async Task ProcessUsingModelPropertyAsync <TModel, TProperty>(TagHelperContext context, TagHelperOutput output,
                                                                                      Expression <Func <TModel, TProperty> > modelProperty)
        {
            var helper = ViewContext.GetHtmlHelper <TModel>();

            if (helper.IsInChameleonFormsField())
            {
                var ff = helper.GetChameleonFormsField();
                output.TagMode = TagMode.StartTagAndEndTag;
                output.TagName = null;
                output.Content.SetHtmlContent(ff.FieldFor(modelProperty, context.GetFieldConfiguration()));
            }
            else if (helper.IsInChameleonFormsSection())
            {
                var s = helper.GetChameleonFormsSection();
                if (output.TagMode == TagMode.SelfClosing)
                {
                    output.TagMode = TagMode.StartTagAndEndTag;
                    output.TagName = null;
                    output.Content.SetHtmlContent(s.FieldFor(modelProperty, context.GetFieldConfiguration()));
                }
                else
                {
                    using (s.BeginFieldFor(modelProperty, context.GetFieldConfiguration()))
                    {
                        var childContent = await output.GetChildContentAsync();

                        childContent.WriteTo(helper.ViewContext.Writer, HtmlEncoder.Default);
                    }

                    output.Content.SetContent("");
                    output.TagName = null;
                }
            }
            else
            {
                throw new NotSupportedException("Attempt to specify a <field> outside of a <form-section>.");
            }
        }
 /// <summary>
 /// Idempotently gets a <see cref="HtmlAttributes"/> from <see cref="TagHelperContext"/> Items.
 /// </summary>
 /// <param name="context">The tag helper context</param>
 /// <returns>The HTML attributes</returns>
 public static HtmlAttributes GetHtmlAttributes(this TagHelperContext context)
 {
     return(context.GetFieldConfiguration().Attributes);
 }
Esempio n. 8
0
        /// <summary>
        /// Called when the tag helper is being processed.
        /// </summary>
        /// <param name="context">The context within which the tag helper is processed</param>
        /// <param name="output">The output from the tag helper</param>
        public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var fc = context.GetFieldConfiguration();

            if (AddClass != null)
            {
                fc.AddClass(AddClass);
            }

            if (Id != null)
            {
                fc.Id(Id);
            }

            if (InlineLabel != null)
            {
                fc.InlineLabel(InlineLabel);
            }

            if (InlineLabelHtml != null)
            {
                fc.InlineLabel(InlineLabelHtml);
            }

            if (InlineLabelHtmlContent != null)
            {
                fc.InlineLabel(InlineLabelHtmlContent);
            }

            if (Placeholder != null)
            {
                fc.Placeholder(Placeholder);
            }

            if (Rows.HasValue)
            {
                fc.Rows(Rows.Value);
            }

            if (Cols.HasValue)
            {
                fc.Cols(Cols.Value);
            }

            if (!string.IsNullOrWhiteSpace(Min))
            {
                fc.Min(Min);
            }

            if (!string.IsNullOrWhiteSpace(Max))
            {
                fc.Max(Max);
            }

            if (Step.HasValue)
            {
                fc.Step(Step.Value);
            }

            if (Disabled.HasValue)
            {
                fc.Disabled(Disabled.Value);
            }

            if (Readonly.HasValue)
            {
                fc.Readonly(Readonly.Value);
            }

            if (Required.HasValue)
            {
                fc.Required(Required.Value);
            }

            switch (As)
            {
            case RenderAs.CheckboxList:
                fc.AsCheckboxList();
                break;

            case RenderAs.RadioList:
                fc.AsRadioList();
                break;

            case RenderAs.Dropdown:
                fc.AsDropDown();
                break;
            }

            if (!string.IsNullOrWhiteSpace(TrueLabel))
            {
                fc.WithTrueAs(TrueLabel);
            }

            if (!string.IsNullOrWhiteSpace(FalseLabel))
            {
                fc.WithFalseAs(FalseLabel);
            }

            if (!string.IsNullOrWhiteSpace(NoneLabel))
            {
                fc.WithNoneAs(NoneLabel);
            }

            if (!string.IsNullOrWhiteSpace(FormatString))
            {
                fc.WithFormatString(FormatString);
            }

            if (HideEmptyItem)
            {
                fc.HideEmptyItem();
            }

            if (Exclude != null)
            {
                fc.Exclude(Exclude);
            }

            if (WithoutInlineLabel)
            {
                fc.WithoutInlineLabel();
            }

            if (InlineLabelWrapsElement.HasValue)
            {
                fc.InlineLabelWrapsElement(InlineLabelWrapsElement.Value);
            }

            fc.Attrs(Attrs);

            return(Task.CompletedTask);
        }
        /// <summary>
        /// Called when the tag helper is being processed.
        /// </summary>
        /// <param name="context">The context within which the tag helper is processed</param>
        /// <param name="output">The output from the tag helper</param>
        public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var fc = context.GetFieldConfiguration();

            if (Append != null)
            {
                fc.Append(Append.ToHtml());
            }

            if (AppendHtml != null)
            {
                fc.Append(AppendHtml);
            }

            if (AppendHtmlContent != null)
            {
                fc.Append(AppendHtmlContent);
            }

            if (Prepend != null)
            {
                fc.Prepend(Prepend.ToHtml());
            }

            if (PrependHtml != null)
            {
                fc.Prepend(PrependHtml);
            }

            if (PrependHtmlContent != null)
            {
                fc.Prepend(PrependHtmlContent);
            }

            if (Hint != null)
            {
                fc.WithHint(Hint);
            }

            if (HintHtml != null)
            {
                fc.WithHint(HintHtml);
            }

            if (HintHtmlContent != null)
            {
                fc.WithHint(HintHtmlContent);
            }

            if (OverrideFieldHtml != null)
            {
                fc.OverrideFieldHtml(OverrideFieldHtml);
            }

            if (OverrideFieldHtmlContent != null)
            {
                fc.OverrideFieldHtml(OverrideFieldHtmlContent);
            }

            if (!string.IsNullOrWhiteSpace(AddContainerClass))
            {
                fc.AddFieldContainerClass(AddContainerClass);
            }

            if (!string.IsNullOrWhiteSpace(HintId))
            {
                fc.WithHintId(HintId);
            }

            return(Task.CompletedTask);
        }