private async Task <string> buildValidationMessageHtml(ModelExplorer property, TweakingConfiguration tweakingConfig)
        {
            PropertyTweakingConfiguration propertyConfig = tweakingConfig.GetByPropertyFullName(property.GetFullName());

            TagHelper validationMessage = new ValidationMessageTagHelper(_htmlGenerator)
            {
                For         = new ModelExpression(property.GetFullName(), property),
                ViewContext = _viewContext
            };

            var errorClassName = propertyConfig?.ValidationClasses;

            if (string.IsNullOrEmpty(errorClassName))
            {
                errorClassName = "text-danger";
            }

            return(await GetGeneratedContentFromTagHelper("span",
                                                          TagMode.StartTagAndEndTag,
                                                          validationMessage,
                                                          new TagHelperAttributeList()
            {
                new TagHelperAttribute("class", propertyConfig?.ValidationClasses)
            }));
        }
示例#2
0
        private async Task <string> buildLabelHtml(ModelExplorer property, TweakingConfiguration tweakingConfig)
        {
            TagHelper label = new LabelTagHelper(_htmlGenerator)
            {
                For         = new ModelExpression(property.GetFullName(), property),
                ViewContext = _viewContext
            };

            PropertyTweakingConfiguration propertyConfig = tweakingConfig
                                                           .GetByPropertyFullName(property.GetFullName());

            return(await GetGeneratedContentFromTagHelper(
                       "label",
                       TagMode.StartTagAndEndTag, label,
                       new TagHelperAttributeList()
            {
                new TagHelperAttribute("class", propertyConfig?.LabelClasses)
            }));
        }
示例#3
0
        private async Task <string> buildInputHtml(ModelExplorer property, TweakingConfiguration tweakingConfig,
                                                   string inputType = "", string inputValue = "", bool radioChecked = false)
        {
            PropertyTweakingConfiguration propertyConfig = tweakingConfig.GetByPropertyFullName(property.GetFullName());

            if (propertyConfig == null || string.IsNullOrEmpty(propertyConfig.InputTemplatePath))
            {
                InputTagHelper input = new InputTagHelper(_htmlGenerator)
                {
                    For         = new ModelExpression(property.GetFullName(), property),
                    ViewContext = _viewContext
                };
                var attrs = new TagHelperAttributeList {
                    new TagHelperAttribute("class", $"form-control {propertyConfig?.InputClasses}")
                };

                if (!string.IsNullOrEmpty(inputType))
                {
                    input.InputTypeName = inputType;
                    input.Value         = inputValue;
                    // Setting the Type attributes requires providing an initialized
                    // AttributeList with the type attribute
                    attrs = new TagHelperAttributeList()
                    {
                        new TagHelperAttribute("class", $"{propertyConfig?.InputClasses}"),
                        new TagHelperAttribute("type", inputType),
                        new TagHelperAttribute("value", inputValue)
                    };
                    if (radioChecked)
                    {
                        attrs.Add(new TagHelperAttribute("checked", "checked"));
                    }
                }

                AutoCompleteAttribute autoComplete;
                if (property.HasAutoComplete(out autoComplete))
                {
                    attrs.AddClass("autocomplete");
                    attrs.Add(getAutoCompleteDataAttribute(autoComplete, property.Container));
                }

                return(await GetGeneratedContentFromTagHelper("input",
                                                              TagMode.SelfClosing,
                                                              input,
                                                              attributes : attrs
                                                              ));
            }
            else
            {
                return(renderInputTemplate(property, propertyConfig.InputTemplatePath));
            }
        }
示例#4
0
        private async Task <string> buildSelectHtml(ModelExplorer property, IEnumerable <SelectListItem> items, TweakingConfiguration tweakingConfig)
        {
            TagHelper select = new SelectTagHelper(_htmlGenerator)
            {
                For         = new ModelExpression(property.GetFullName(), property),
                ViewContext = _viewContext,
                Items       = items
            };

            return(await GetGeneratedContentFromTagHelper("select",
                                                          TagMode.StartTagAndEndTag,
                                                          select,
                                                          new TagHelperAttributeList { new TagHelperAttribute("class", "form-control dropdown") }));
        }