Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Issue using ConfirmDialog and Toasts alongside EditForm

$
0
0

Good morning. I hope you can help me.

I am trying to use the ConfirmDialog and Toasts components.

If I run it from any component, it works perfectly:Example:

    @page "/counter"    @rendermode InteractiveServer<PageTitle>Counter</PageTitle><h1>Counter</h1><p role="status">Current count: @currentCount</p><button class="btn btn-primary" @onclick="IncrementCount">Click me</button><button class="btn btn-primary" @onclick="IncrementCount1">Click Toasts</button><button class="btn btn-primary" @onclick="IncrementCount2">Click ConfirmDialog</button>    @if (toastParametros.Visible){<_Toast toastParametros="toastParametros"></_Toast>} <ConfirmDialog @ref="confirmDialog" />    @code {        private int currentCount = 0;        private ToastParametros toastParametros = new ToastParametros();         private ConfirmDialog confirmDialog;        private void IncrementCount()        {            currentCount++;        }        private void IncrementCount1()        {                toastParametros.Type = ToastType.Info;                toastParametros.IconName = IconName.Alarm;                toastParametros.Title = "title";                toastParametros.Message = $"info saved.";                toastParametros.Visible = true;        }        private void IncrementCount2()        {             var confirmation = confirmDialog.ShowAsync("Confir", "¿save the changes?");        }    }

The problem occurs when I use EditForm, as neither ConfirmDialog nor Toasts become visible, despite being invoked. When you click the save button, the browser remains "loading."

Example Code:

@page "/prueba"<!-- Form Fields Here --><div class="row"><div class="col-md-12 text-center"><Button Color="ButtonColor.Success" Size="ButtonSize.Medium" Type="ButtonType.Submit" ><Icon CustomIconName="fas fa-save" /> Save</Button><Button Color="ButtonColor.Secondary" Size="ButtonSize.Medium" Type="ButtonType.Link"><Icon CustomIconName="fas fa-times" /> go back</Button></div></div><ConfirmDialog @ref="dialog" />@code {    private ConfirmDialog dialog = default!;    private Cliente Model = new Cliente();    private async Task HandleSubmit(EditContext context)    {    try    {    if (context.Validate())    {    var confirmation = await ShowConfirmation();    if (confirmation)    {    await Insert(Model);    }    }    }    catch (Exception ex)    {    Console.WriteLine($"Error: {ex.Message}");    }    }    private async Task<bool> ShowConfirmation()    {        var options = new ConfirmDialogOptions        {            YesButtonText = "OK",            NoButtonText = "Cancelar"        };        return await dialog.ShowAsync("Confirmar", "¿Confirma los cambios?", options);    }    private async Task Insert(Cliente cliente)    {        // Your insert logic here    }    public class Cliente    {        public string Name { get; set; }        public int Age { get; set; }    }}
**I can't solve it, I can't find error(s) in the browser console, nor in the debugging console.**

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>