This is a migrated thread and some comments may be shown as answers.

enter key on selected command button in command bar saves record instead of fires command

5 Answers 152 Views
Grid
This is a migrated thread and some comments may be shown as answers.
FvLent
Top achievements
Rank 2
FvLent asked on 19 Sep 2012, 09:36 AM
Hi,
I have a radgrid with a custom command bar (commanditemtemplate) with a few linkbuttons on it.
Also I have the radgrid ClientSettings AllowKeyboardNavigation="true" and KeyboardNavigationSettings AllowSubmitOnEnter="true"
When I move to the command bar with the TAB key  and select a linkbutton (or use the associated AccessKey to select it immedeately), then use the ENTER key to fire the button, instead the selected record is opened for editing.
How can I skip the SubmitOnEnter when I have the linkbutton selected?

I tried the code below, it gets fired when the enter key is pressed, but still the record is selected instead of the command fired.
Any ideas?

Thanx in advance,

Regards,
Frank
Telerik.Web.UI.RadGrid.prototype._canHandleKeyboardAction = function (e) {
                var keyCode = e.keyCode || e.charCode;
                if ((keyCode == 32 || keyCode == 13)
                && this.ClientSettings.KeyboardNavigationSettings.EnableKeyboardShortcuts) {
                    var target = Telerik.Web.UI.Grid.GetCurrentElement(e);
                    if (target.tagName.toLowerCase() == "a") {                        
                        return false;
                    }
                }
                return true;
            }

5 Answers, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 24 Sep 2012, 06:01 AM
Hello Frank,

I have assembled a sample project trying to replicate the issue but to no avail. You could take a look at the attached page in order to observe if there any differences at your end. Additionally, I have created a video showing the behavior on my side.

Kind regards,
Antonio Stoilkov
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.
0
FvLent
Top achievements
Rank 2
answered on 24 Sep 2012, 12:51 PM
Hi Antonio,

Thank you for the reply.
I tried your page, and it gives me the same results as I had, behaving not as I wanted.
In your video it looks like it works OK, but I doubt if you did exactly as I did.
In your page, did you:
   1. select the Linkbutton (example by right-clicking on the linkbutton, or, after loading the page, use the Tab Key four times to select the linkbutton)
   2. Then press the Enter-key on the keyboard to fire the link-button's action.

In my case, then, the first record goes into edit-mode. I want the linkbutton to perform the action.

Regards,

Frank
0
Antonio Stoilkov
Telerik team
answered on 27 Sep 2012, 08:27 AM
Hi Frank,

I have further tested the project and successfully replicated the issue when a row is selected and press enter when the LinkButton control is focused. The experienced behavior is expected because RadGrid opens the currently selected item in edit mode regarding the focused element. However, you could achieve your scenario by subscribing to RadGrid OnKeyPress client side event and in the handler function cancel the event when the target is the LinkButton control.
<ClientEvents OnKeyPress="KeyPress" />
function KeyPress(sender, eventArgs)
{
    var target = eventArgs.get_domEvent().target;
    if (eventArgs.get_keyCode() == 13 && target.id.endsWith("LinkButtonSetLabelText"))
    {
        eventArgs.set_cancel(true);
    }
}

All the best,
Antonio Stoilkov
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.
0
FvLent
Top achievements
Rank 2
answered on 28 Sep 2012, 09:30 AM
Hi Antonio,

Your solution works perfectly.
To make this work for all linkbuttons (in the command-bar and the ones in the grid itself, for example, the Save, Cancel and Delete linkbuttons in the edit-item row), I suggest to change the code to:
function KeyPress(sender, eventArgs){
var target = eventArgs.get_domEvent().target;
if (eventArgs.get_keyCode() == 13 && target.tagName.toLowerCase() == 'a'){
eventArgs.set_cancel(true);
}
}

I don't agree with your statement that the enter-key behaviour is "as expected". I expect the selected record to open ONLY WHEN a record is selected, not when a button is selected! I really think Telerik should change the default enter-key behaviour similar to the solution above. Maybe you can submit this as a change request or bug fix?

Regards,

Frank

0
Antonio Stoilkov
Telerik team
answered on 03 Oct 2012, 06:23 AM
Hi Frank,

I have contacted our development team and logged the idea as a feature request. Note that decisions for which features to be implemented are based on customer demand rates and the control needs.

All the best,
Antonio Stoilkov
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.
Tags
Grid
Asked by
FvLent
Top achievements
Rank 2
Answers by
Antonio Stoilkov
Telerik team
FvLent
Top achievements
Rank 2
Share this question
or