Last Updated: 07 May 2021 00:29 by Baires
Created on: 06 Apr 2021 12:41
Category: Dialog
Type: Feature Request
Be able to make Cancel the default button

Can I define the Cancel home button by default? When deleting a line I use Confirm Dialogs, I want the default (active) button to be Cancel (not Ok)



Here is a solution you can use:

@inject IJSRuntime _js

@* move this script to a proper place in your project and remove the 
    suppress-error hack that lets it stay in the component - it is here for brevity only *@
<script suppress-error="BL9992">
    function focusCancelDialogButton() {
        setTimeout(function() {
            var cancelButtons = document.querySelectorAll(".k-dialog .k-dialog-buttongroup .k-button");
            if(cancelButtons && cancelButtons.length > 1) {
        }, 100);

<TelerikButton OnClick="@ShowConfirm">Show Confirm</TelerikButton>

@code {
    public DialogFactory Dialogs { get; set; }

    public async Task ShowConfirm()
        await _js.InvokeVoidAsync("focusCancelDialogButton");
        bool isConfirmed = await Dialogs.ConfirmAsync("Are you sure?");

        if (isConfirmed)
            Console.WriteLine("The user is sure, continue.");
            Console.WriteLine("The user changed their mind");


1 comment
Posted on: 07 May 2021 00:29

I suggest creating a third overload with an enum(DialogActions) parameter Ok and Cancel

public Task<bool> ConfirmAsync(string text, string title, DialogActions defaultAction);