Open Closed

Choose only one role while creating a user #3179


User avatar
0
safi created

Hi

I want to add functionality to choose only one role. Currently we can choose more that one in user creation popup so can you please suggest how we can do this.

  • ABP Framework version: v4.43
  • UI type: Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

5 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You need to customize the page.

    See the document to know how to do it: https://docs.abp.io/en/abp/latest/UI/Blazor/Customization-Overriding-Components?UI=Blazor

    We are using checkboxes here, you can replace them with radio: https://blazorise.com/docs/components/radio

  • User Avatar
    0
    safi created

    Hi,

    You need to customize the page.

    See the document to know how to do it: https://docs.abp.io/en/abp/latest/UI/Blazor/Customization-Overriding-Components?UI=Blazor

    We are using checkboxes here, you can replace them with radio: https://blazorise.com/docs/components/radio

    I am using this code but it's not inserting correct role id.

    foreach (var role in NewUserRoles)
    {
        <Field>
            <input type="hidden" @bind-value="@role.Name" />
            <Radio TValue="string" Name="allRole" Value="@(role.Name)">@role.Name</Radio>
           @* <Check TValue="bool" @bind-Checked="@role.IsAssigned">@role.Name</Check>*@
        </Field>
    }
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    You can try this:

    foreach (var role in NewUserRoles)
    {
        <Field>
    	<input type="hidden" @bind-value="@role.Name" />
    	<Check TValue="bool" Checked="@role.IsAssigned" CheckedChanged="@(v => OnSelectedRoleChangeAsync(role.Name, v))">@role.Name</Check>
        </Field>
    }
      
    Task OnSelectedRoleChangeAsync(string roleName, bool value)
    {
       var role = NewUserRoles.FirstOrDefault(x => x.Name == roleName);
       role.IsAssigned = value;
       if (value)
       {
          foreach (var item in NewUserRoles)
          {
    	    if (item.Name != roleName)
    	    {
    		    item.IsAssigned = false;
    	    }
          }
       }
    
       return Task.CompletedTask;
    }
    
  • User Avatar
    0
    safi created

    foreach (var role in NewUserRoles) { <Field> <input type="hidden" @bind-value="@role.Name" /> <Check TValue="bool" Checked="@role.IsAssigned" CheckedChanged="@(v => OnSelectedRoleChangeAsync(role.Name, v))">@role.Name</Check> </Field> }

    Thanks much!

  • User Avatar
    0
    safi created

    foreach (var role in NewUserRoles) { <Field> <input type="hidden" @bind-value="@role.Name" /> <Check TValue="bool" Checked="@role.IsAssigned" CheckedChanged="@(v => OnSelectedRoleChangeAsync(role.Name, v))">@role.Name</Check> </Field> }

    Thanks much!

Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19