Open Closed

Angular input based on Enum type Extra Property not visible due to its type being set to hidden #8442


User avatar
0
stefan@climatecamp.io created
  • ABP Framework version: v8.2.1
  • UI Type: Angular
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace: multiple warnings in console
  • Steps to reproduce the issue:
  1. Create a new Enum
  2. Extend an existing module following the abp documentation and set the new property type as the new Enum.
  3. Angular frontend renders the Label but not the dropdown.

This happens both with our current abp version as well as with a new solution using abp v9.0.1, .net 9 and Angular v18.

Edit: at least in the new solution, removing the null annotation seems to fix the issue and renders the input, but at least in our case the property should be nullable so this would not be a fix.


6 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hello,

    As per you are saying i have try reproduce the issue but at my side it work fine. I have shared some Screenshots.

    Thank you.

  • User Avatar
    0
    stefan@climatecamp.io created

    Thanks for the reply, have you tried setting it as nullable as per the abp documentation itself and similar with my example and use case?

  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    I have tried with your example and use case its work fine.

    have you tried setting it as nullable as per the abp documentation itself

    Can you explain in details and which document you can refer.

  • User Avatar
    0
    stefan@climatecamp.io created

    I have tried with your example and use case its work fine.

    have you tried setting it as nullable as per the abp documentation itself

    Can you explain in details and which document you can refer.

    sorry, I should have been more clear in my initial repro steps: Steps to reproduce the issue:

    1. Create a new Enum
    2. Extend an existing module following the abp documentation, set the new property type as the new Enum and set is as nullable.
    3. Angular frontend renders the Label but not the dropdown.

    See screenshot bellow, same one as the initial one, line 78, "<OrganizationStatus?>"

    I'm not sure what exactly you mean by "which document you can refer", maybe the abp documentation itself if you click on the link.

    Screenshot from the documentation below in which it's explained how to handle nullable Enums.

  • User Avatar
    0
    sumeyye.kurtulus created
    Support Team Angular Expert

    Hello, thank you for reporting this. We will be fixing the problem as soon as possible and refunding your ticket.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    We will fix this in the next version. You can temporarily solve it by replace the CachedObjectExtensionsDtoService

    https://github.com/abpframework/abp/pull/21675

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending;
    using Volo.Abp.DependencyInjection;
    using Volo.Abp.ObjectExtending;
    using Volo.Abp.ObjectExtending.Modularity;
    
    namespace MyCompanyName.MyProjectName.Web;
    
    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(MyCachedObjectExtensionsDtoService), typeof(CachedObjectExtensionsDtoService), typeof(ICachedObjectExtensionsDtoService))]
    public class MyCachedObjectExtensionsDtoService : CachedObjectExtensionsDtoService
    {
        public MyCachedObjectExtensionsDtoService(IExtensionPropertyAttributeDtoFactory extensionPropertyAttributeDtoFactory)
            : base(extensionPropertyAttributeDtoFactory)
        {
    
        }
    
        protected override void FillEnums(ObjectExtensionsDto objectExtensionsDto)
        {
            var enumProperties = ObjectExtensionManager.Instance.Modules().Values
                .SelectMany(
                    m => m.Entities.Values.SelectMany(
                        e => e.GetProperties()
                    )
                )
                .Where(p => p.Type.IsEnum || IsNullableEnum(p.Type))
                .ToList();
    
            foreach (var enumProperty in enumProperties)
            {
                // ReSharper disable once AssignNullToNotNullAttribute (enumProperty.Type.FullName can not be null for this case)
                objectExtensionsDto.Enums[enumProperty.Type.FullName!] = CreateExtensionEnumDto(enumProperty);
            }
        }
    
        protected override ExtensionEnumDto CreateExtensionEnumDto(ExtensionPropertyConfiguration enumProperty)
        {
            var extensionEnumDto = new ExtensionEnumDto
            {
                Fields = new List<ExtensionEnumFieldDto>(),
                LocalizationResource = enumProperty.GetLocalizationResourceNameOrNull()
            };
    
            var enumType = enumProperty.Type.IsEnum
                ? enumProperty.Type
                : IsNullableEnum(enumProperty.Type)
                    ? Nullable.GetUnderlyingType(enumProperty.Type)
                    : null;
    
            if (enumType == null)
            {
                return extensionEnumDto;
            }
    
            foreach (var enumValue in enumType.GetEnumValues())
            {
                extensionEnumDto.Fields.Add(
                    new ExtensionEnumFieldDto
                    {
                        Name = enumType.GetEnumName(enumValue)!,
                        Value = enumValue
                    }
                );
            }
    
            return extensionEnumDto;
        }
    
        public bool IsNullableEnum(Type type)
        {
            return type.IsGenericType &&
                   type.GetGenericTypeDefinition() == typeof(Nullable<>) &&
                   type.GenericTypeArguments.Length == 1 &&
                   type.GenericTypeArguments[0].IsEnum;
        }
    }
    
    
Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09