Can you please provide documentation on how to implement Ajax with the PreConfirm Callback?
ohenebaamissah opened this issue · comments
Awesome Blazor wrapper for the SweetAlert library.
I'd like to use the Ajax feature but the code below (sweetAlert2 Ajax Sample) doesn't work.
async Task ShowGithubAvatar()
{
try
{
var result = await Swal.FireAsync(new SweetAlertOptions
{
Title = "Submit your Github username",
Input = SweetAlertInputType.Text,
InputAttributes = new Dictionary<string, string> { { "autoCapitalize", "off" } },
ShowCancelButton = true,
ConfirmButtonText = "Look Up",
ShowLoaderOnConfirm = true,
PreConfirm = new PreConfirmCallback(async (username) => {
var response = await Http.GetAsync($"https://api.github.com/users/{username}");
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
}, this),
AllowOutsideClick = await Swal.IsLoadingAsync()
});
if (!string.IsNullOrEmpty(result.Value))
{
dynamic githubProfile = JToken.Parse(result.Value);
await Swal.FireAsync(new SweetAlertOptions
{
Title = $"{githubProfile.login}'s avatar",
ImageUrl = githubProfile.avatar_url
});
}
}
catch (Exception ex)
{
await Swal.ShowValidationMessageAsync($"Request failed: {ex.Message}");
}
}
Can you please provide some clarification around this?