Unplanned
Last Updated: 26 Mar 2024 11:41 by ADMIN
Dan
Created on: 20 Aug 2021 08:13
Category: Dialog
Type: Feature Request
12
Enter should trigger the Ok button in a prompt dialog
Pressing the Enter key should trigger the Ok button in the Prompt Dialog
4 comments
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!