Updated all forms to use the EnhancedEditForm and blazors native validation. Fixed smaller issues after upgrading to ShadcnBlazor 1.0.11
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
@using Moonlight.Frontend.UI.Admin.Components
|
||||
@using Moonlight.Shared.Http.Requests.Roles
|
||||
@using ShadcnBlazor.Buttons
|
||||
@using ShadcnBlazor.Dialogs
|
||||
@using ShadcnBlazor.Extras.Common
|
||||
@using ShadcnBlazor.Extras.FormHandlers
|
||||
@using ShadcnBlazor.Extras.Forms
|
||||
@using ShadcnBlazor.Fields
|
||||
@using ShadcnBlazor.Inputs
|
||||
@using ShadcnBlazor.Labels
|
||||
|
||||
@inherits ShadcnBlazor.Extras.Dialogs.DialogBase
|
||||
|
||||
@@ -18,41 +16,36 @@
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<FormHandler @ref="FormHandler" Model="Request" OnValidSubmit="OnSubmitAsync">
|
||||
<div class="flex flex-col gap-6">
|
||||
|
||||
<EnhancedEditForm Model="Request" OnValidSubmit="OnSubmitAsync">
|
||||
<FieldGroup>
|
||||
<FormValidationSummary/>
|
||||
<DataAnnotationsValidator/>
|
||||
|
||||
<div class="grid gap-2">
|
||||
<Label for="roleName">Name</Label>
|
||||
<TextInputField
|
||||
@bind-Value="Request.Name"
|
||||
id="roleName"
|
||||
placeholder="My fancy role"/>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-2">
|
||||
<Label for="roleDescription">Description</Label>
|
||||
<textarea
|
||||
@bind="Request.Description"
|
||||
id="roleDescription"
|
||||
maxlength="100"
|
||||
class="border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm"
|
||||
placeholder="Describe what the role should be used for">
|
||||
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-2">
|
||||
<Label>Permissions</Label>
|
||||
<PermissionSelector Permissions="Permissions" />
|
||||
</div>
|
||||
</div>
|
||||
</FormHandler>
|
||||
|
||||
<DialogFooter ClassName="justify-end gap-x-1">
|
||||
<WButtom OnClick="SubmitAsync">Save changes</WButtom>
|
||||
</DialogFooter>
|
||||
<FieldSet>
|
||||
<Field>
|
||||
<FieldLabel for="roleName">Name</FieldLabel>
|
||||
<TextInputField
|
||||
@bind-Value="Request.Name"
|
||||
id="roleName"
|
||||
placeholder="My fancy role"/>
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel for="keyDescription">Description</FieldLabel>
|
||||
<TextareaInputField @bind-Value="Request.Description" id="keyDescription"
|
||||
placeholder="Describe what the role should be used for"/>
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel>Permissions</FieldLabel>
|
||||
<FieldContent>
|
||||
<PermissionSelector Permissions="Permissions"/>
|
||||
</FieldContent>
|
||||
</Field>
|
||||
</FieldSet>
|
||||
<Field Orientation="FieldOrientation.Horizontal" ClassName="justify-end">
|
||||
<SubmitButton>Save changes</SubmitButton>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
</EnhancedEditForm>
|
||||
|
||||
@code
|
||||
{
|
||||
@@ -60,7 +53,6 @@
|
||||
|
||||
private CreateRoleDto Request;
|
||||
private List<string> Permissions;
|
||||
private FormHandler FormHandler;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
@@ -68,19 +60,17 @@
|
||||
{
|
||||
Permissions = []
|
||||
};
|
||||
|
||||
|
||||
Permissions = new();
|
||||
}
|
||||
|
||||
private async Task SubmitAsync()
|
||||
private async Task<bool> OnSubmitAsync(EditContext editContext, ValidationMessageStore validationMessageStore)
|
||||
{
|
||||
Request.Permissions = Permissions.ToArray();
|
||||
await FormHandler.SubmitAsync();
|
||||
}
|
||||
|
||||
private async Task OnSubmitAsync()
|
||||
{
|
||||
await OnSubmit.Invoke(Request);
|
||||
await CloseAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user