Browse Source

Blazorise client side validation for RoleManagementBase

pull/5973/head
Mladen Macanovic 6 years ago
parent
commit
56fce17d70
  1. 28
      modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor
  2. 15
      modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs

28
modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor

@ -78,26 +78,32 @@
{ {
<Modal @ref="CreateModal"> <Modal @ref="CreateModal">
<ModalBackdrop /> <ModalBackdrop />
<ModalContent IsCentered="true"> <ModalContent Centered="true">
<ModalHeader> <ModalHeader>
<ModalTitle>@L["NewRole"]</ModalTitle> <ModalTitle>@L["NewRole"]</ModalTitle>
<CloseButton Clicked="CloseCreateModalAsync" /> <CloseButton Clicked="CloseCreateModalAsync" />
</ModalHeader> </ModalHeader>
<ModalBody> <ModalBody>
<EditForm id="IdentityRoleCreateForm" Model="@NewEntity" OnValidSubmit="CreateEntityAsync"> <Validations @ref="@ValidationsRef" Mode="ValidationMode.Auto" Model="@NewEntity" ValidateOnLoad="false">
<Validation>
<Field>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel>
<TextEdit @bind-Text="@NewEntity.Name">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Field> <Field>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel> <Check TValue="bool" @bind-Checked="@NewEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
<TextEdit @bind-text="@NewEntity.Name"/> <Check TValue="bool" @bind-Checked="@NewEntity.IsPublic">@L["DisplayName:IsPublic"]</Check>
</Field>
<Field>
<Check TValue="bool" @bind-checked="@NewEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
<Check TValue="bool" @bind-checked="@NewEntity.IsPublic">@L["DisplayName:IsPublic"]</Check>
</Field> </Field>
</EditForm> </Validations>
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseCreateModalAsync">@L["Cancel"]</Button> <Button Color="Color.Secondary" Clicked="CloseCreateModalAsync">@L["Cancel"]</Button>
<Button form="IdentityRoleCreateForm" Color="Color.Primary" Clicked="CreateEntityAsync">@L["Save"]</Button> <Button Color="Color.Primary" Clicked="OnCreateEntityClicked">@L["Save"]</Button>
</ModalFooter> </ModalFooter>
</ModalContent> </ModalContent>
</Modal> </Modal>
@ -107,7 +113,7 @@
{ {
<Modal @ref="EditModal"> <Modal @ref="EditModal">
<ModalBackdrop /> <ModalBackdrop />
<ModalContent IsCentered="true"> <ModalContent Centered="true">
<ModalHeader> <ModalHeader>
<ModalTitle>@L["Edit"]</ModalTitle> <ModalTitle>@L["Edit"]</ModalTitle>
<CloseButton Clicked="CloseEditModalAsync" /> <CloseButton Clicked="CloseEditModalAsync" />

15
modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Blazorise;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.BlazoriseUI; using Volo.Abp.BlazoriseUI;
@ -17,6 +18,8 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected bool ShouldShowEntityActions { get; set; } protected bool ShouldShowEntityActions { get; set; }
protected Validations ValidationsRef { get; set; }
public RoleManagementBase() public RoleManagementBase()
{ {
ObjectMapperContext = typeof(AbpIdentityBlazorModule); ObjectMapperContext = typeof(AbpIdentityBlazorModule);
@ -38,5 +41,17 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
HasDeletePermission || HasDeletePermission ||
HasManagePermissionsPermission; HasManagePermissionsPermission;
} }
protected virtual Task OnCreateEntityClicked()
{
if ( ValidationsRef.ValidateAll() )
{
CreateModal.Hide();
return CreateEntityAsync();
}
return Task.CompletedTask;
}
} }
} }

Loading…
Cancel
Save