Unplanned
Last Updated: 12 Apr 2021 07:38 by ADMIN
Yuri
Created on: 06 Apr 2021 12:41
Category: Dialog
Type: Feature Request
1
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)

---

ADMIN EDIT

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) {
                cancelButtons[1].focus();
            }
        }, 100);
    }
</script>

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

@code {
    [CascadingParameter]
    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.");
        }
        else
        {
            Console.WriteLine("The user changed their mind");
        }
    }
}

---

0 comments