Unplanned
Last Updated: 16 Jul 2024 11:59 by ADMIN
Dan
Created on: 20 Aug 2021 08:13
Category: Dialog
Type: Feature Request
13
Enter should trigger the Ok button in a prompt dialog
Pressing the Enter key should trigger the Ok button in the Prompt Dialog
7 comments
ADMIN
Hristian Stefanov
Posted on: 16 Jul 2024 11:59

Hi René,

Thank you for sharing an extended version of the workaround.

I can confirm that until August, at least, our backlog/short-term planning is filled with items of more priority and demand. Thus, the status here is still unplanned.

Regards,
Hristian Stefanov
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
René
Posted on: 16 Jul 2024 05:59

This is an extended version of the workaround handling both ENTER (primary button) and ESC (base button):

function addKeyDownHandlerForTelerikDialogs() {
document.body.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
if (event.target.classList.contains("k-input-inner") && event.target.closest(".k-dialog")) {
const dialog = event.target.closest(".k-dialog");
const okButton = dialog.querySelector(".k-button-solid-primary");
if (okButton) {
okButton.click();
}
}
}
if (event.key === "Escape") {
if (event.target.classList.contains("k-input-inner") && event.target.closest(".k-dialog")) {
const dialog = event.target.closest(".k-dialog");
const cancelButton = dialog.querySelector(".k-button-solid-base");
if (cancelButton) {
cancelButton.click();
}
}
}
});
}
René
Posted on: 16 Jul 2024 05:40

Still no plans of finally providing this feature?
The ConfirmDelete Dialog in your grid already has the feature of being accepted with ENTER and cancelled with ESC so it should be no rocket science to implement that for all your default dialogs  (if you do implement it please don't stop with prompt dialog but do it for Alert and Confirm dialogs as well).

I'm grateful for provided javascript workarounds but providing those should not block the implementation of Feature Requests.  As I've mentioned on other occasions as well - I'm using Blazor to get rid of as much javascript as possible and I'm using Telerik components to save as much time as possible.

Regards,

René

ADMIN
Hristian Stefanov
Posted on: 26 Mar 2024 11:41

Hi Lance,

I have spent time searching for a possible workaround, and I have found the following:

@inject IJSRuntime JSRuntime

<TelerikButton OnClick="@ShowPrompt">Show Prompt</TelerikButton>

@* move this script to an actual script file instead of using this hack *@
<script suppress-error="BL9992">
    function addKeyDownHandler() {
        document.body.addEventListener("keydown", function (event) {
            if (event.key === "Enter") {
                if (event.target.classList.contains("k-input-inner") && event.target.closest(".k-dialog")) {
                    const dialog = event.target.closest(".k-dialog");
                    const okButton = dialog.querySelector(".k-button");
                    if (okButton) {
                        okButton.click();
                    }
                }
            }
        });
    }
</script>

@code {
    [CascadingParameter]
    private DialogFactory Dialogs { get; set; }

    private async Task ShowPrompt()
    {
        await JSRuntime.InvokeVoidAsync("addKeyDownHandler");

        string userInput = await Dialogs.PromptAsync("Enter your answer.");

        if (userInput == null)
        {
            Console.WriteLine("The user will not answer.");
        }
        else
        {
            Console.WriteLine($"The user said: {userInput}");
        }
    }
}

The steps:

  1. Create a small JavaScript function
  2. Within it, add a keydown handler to the page <body> element and check if the key is Enter and the target is a TextBox inside a Dialog
  3. Then, if true, find and click() the OK button in the Dialog

Regards,
Hristian Stefanov
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
Lance
Posted on: 20 Mar 2024 02:44
Is there a recommended workaround for this? javascript code etc?
ADMIN
Hristian Stefanov
Posted on: 06 Mar 2024 06:55

Hi Marco,

Thank you for showing your interest in the feature request.

I confirm the feature status is still "Unplanned" at this stage. That means no specific time frame has been assigned yet. As soon as we move a task to the short-term backlog, the status will change to "Planned" and most likely an indicative month for releasing it will appear as well.

Regards,
Hristian Stefanov
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
Marco
Posted on: 05 Mar 2024 10:55

Hello,

 

any news about this request? Should be something usefull also for our application.

Thanks!