Exemplo n.º 1
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));
            }
        }