74 lines
2.1 KiB
Plaintext
74 lines
2.1 KiB
Plaintext
@using Moonlight.Frontend.Helpers
|
|
@using MoonlightServers.Shared
|
|
@using MoonlightServers.Shared.Http.Requests
|
|
@using MoonlightServers.Shared.Http.Responses
|
|
@using ShadcnBlazor.Buttons
|
|
@using ShadcnBlazor.Dialogs
|
|
@using ShadcnBlazor.Extras.AlertDialogs
|
|
@using ShadcnBlazor.Extras.Forms
|
|
@using ShadcnBlazor.Fields
|
|
@using ShadcnBlazor.Inputs
|
|
|
|
@inherits ShadcnBlazor.Extras.Dialogs.DialogBase
|
|
|
|
@inject HttpClient HttpClient
|
|
@inject AlertDialogService AlertDialogService
|
|
|
|
<DialogHeader>
|
|
<DialogTitle>Example Form</DialogTitle>
|
|
<DialogDescription>This forms removes all spaces from the input</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<EnhancedEditForm @ref="Form" OnValidSubmit="OnSubmit" Model="Dto">
|
|
<DataAnnotationsValidator/>
|
|
|
|
<FieldSet>
|
|
<FormValidationSummary/>
|
|
|
|
<FieldGroup>
|
|
<Field>
|
|
<FieldLabel for="formInput">Form Input</FieldLabel>
|
|
<TextInputField id="formInput" @bind-Value="Dto.TextField"/>
|
|
<FieldDescription>Input you want to remove the spaces from</FieldDescription>
|
|
</Field>
|
|
</FieldGroup>
|
|
</FieldSet>
|
|
</EnhancedEditForm>
|
|
|
|
<DialogFooter>
|
|
<Button @onclick="() => Form.SubmitAsync()">Submit</Button>
|
|
<DialogClose/>
|
|
</DialogFooter>
|
|
|
|
@code
|
|
{
|
|
private FormSubmitDto Dto = new();
|
|
private EnhancedEditForm Form;
|
|
|
|
private async Task<bool> OnSubmit(EditContext editContext, ValidationMessageStore validationMessageStore)
|
|
{
|
|
var response = await HttpClient.PostAsJsonAsync(
|
|
"api/form",
|
|
Dto,
|
|
SerializationContext.Default.Options
|
|
);
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var data = await response.Content.ReadFromJsonAsync<FormResultDto>(
|
|
SerializationContext.Default.Options
|
|
);
|
|
|
|
if (data == null)
|
|
return true;
|
|
|
|
await AlertDialogService.InfoAsync("Result", data.Result);
|
|
|
|
await CloseAsync();
|
|
return true;
|
|
}
|
|
|
|
await ProblemDetailsHelper.HandleProblemDetailsAsync(response, Dto, validationMessageStore);
|
|
return false;
|
|
}
|
|
} |