Set focus on Cancel button when radConfirm is called

5 posts, 0 answers
  1. Nainil
    Nainil avatar
    3 posts
    Member since:
    Nov 2011

    Posted 03 Nov 2011 Link to this post

    I am simply calling radConfirm which opens up the default "OK" and "Cancel" buttons. However the "Cancel" button does not have focus.
       Is there a property or client side code that can set focus on "Cancel" button
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3600 posts

    Posted 04 Nov 2011 Link to this post

    Hi Nainil,

    By default the OK button is closed as this is the behavior of the browser confirm dialog. Therefore there is no simple property to change it. You can, however, use some JavaScript to focus the element you wish:
    var oConfirm = radconfirm("sure?", alertUserResponse);//gets a reference to the confirm popup
    var elementList = $telerik.$(".rwPopupButton", oConfirm.get_popupElement());//gets reference to the buttons in the confirm
    setTimeout(function ()
    {
        elementList[1].focus();//focuses the second button, which is the cancel
    }, 0);

    I am also attaching a simple page that shows this in action.

    Kind regards,
    Marin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Nainil
    Nainil avatar
    3 posts
    Member since:
    Nov 2011

    Posted 07 Nov 2011 Link to this post

    Marin,
        Thanks for the response. That does help. However when the confirm window comes up with the Cancel button having focus, if I tab out using the tab key, I can keep on tabbing to go through few of the IE's input controls (such as back, and forward buttons, url textBox, etc) and eventually, the focus comes back to the form on which the confirm window is still visible. Suppose I have a logout link at the top of my page, then on tabbing a few times, the logout link will gain focus and I can logout without even hitting the Cancel button.
        Is there any setting to prevent the parent form stealing focus when tabbing after the confirm button is opened, but before any action such as "Cancel" or "OK" have been performed?
           Thanks.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Nov 2011 Link to this post

    Hello Nainil,

    Check the following forum thread which discuss the same.
    Tabbing between Ok and Cancel buttons on RadConfirm window

    Thanks,
    Princy.
  6. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3600 posts

    Posted 08 Nov 2011 Link to this post

    Hello guys,

    Let me point out that currently a modal RadWindow (which is what the RadConfirm is) changes the tabIndex property of all input elements and other elements for which it is relevant to -1 when it is shown. This means that you cannot tab to the page as you can see in the video I recorded: http://screencast.com/t/tL9jUpuhdlut. I used the previously attached page as basis and simply added a textbox that alerts when it gets focus.

    It is also important to note that if you expect the keyboard to be used as a navigation tool you would need to prepare your page accordingly - i.e. set tabIndex and accessKey properties where needed. TabIndex is needed for all elements that trigger action when clicked - such as buttons, anchors, inputs, etc, accessKey usage is a developer decision. If a page is not properly configured for keyboard support some unexpected behavior may arise for which we cannot take care of as this is an invalid scenario.


    All the best,
    Marin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017