Open Closed

[Form Prop Extension] - How can I set the defaultValue from one of the options in a dropdown? #8517


User avatar
0
trannguyenphucanh created

Hi Support Team,

I have an API that retrieves a user list to display in the dropdown. The user object includes a flag (isDefault) to indicate the default user, which is automatically set for the dropdown when creating an employee within the application.

However, I am stuck trying to set the defaultValue to the user marked as the default. How can I address this issue?

For more details, please see my screenshot.

Hope to hearing from you guys soon. Thanks

  • ABP Framework version: v8.0.4
  • UI Type: Angular
  • Database System: EF Core
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • Steps to reproduce the issue:
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

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

    Hello

    Can you once try to this code If it is helpful for you.

            options: data =>
                {
                    const service = data.getInjected(UserService);
                    return service
                        .getList({
                            filterText: '',
                            roleName: UserRole.Admin + ',' + UserRole.CountryManager + ',' + UserRole.LineManager,
                            isFromEditUser: true
                        })
                        .pipe(
                            map((data: UserDto[]) => {
                                const items = data.filter(x => !x.isLockedOut);
                                // Find the user marked as default
                                const index = items.findIndex(x => x.isDefault);
                                const userDefault = index !== -1 ? `${items[index].id}` : null; // Handle case where no default user exists
                                
                                // Return both the options and the default value
                                return {
                                    items: items.map(item => ({
                                        key: item.fullName,
                                        value: item.id
                                    })),
                                    defaultValue: userDefault
                                };
                            })
                        );
                },
            defaultValue: data => data.defaultValue, // Bind the default value here
            isExtra: prop.isExtra,
            // Your validation logic
        });
    }
    
    

    Thank you

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    trannguyenphucanh created

    Hi @Anjali_Musmade Thank you for reaching out. I tried, but it is not working as expected. We should pass the correct type.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Member

    Can you share your sample code and steps to reproduce this issue.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    trannguyenphucanh created

    My expectation is that the dropdown will automatically fill in the data for the item where isDefault is true when creating new an user. However, I am stuck in here.

    And here are screenshots of the create Form Prop Contributes.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Member

    Hello

    Please chek this link https://abp.io/support/questions/7298/Angular-Identity-and-Account-form-extensions-set-default-value-using-extra-properties#answer-3a1303f3-aadd-04de-88e5-250c8dbb773f

    Thank you

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 28, 2026, 11:44
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.