Stop Enter (13) with Single Edit Box on XPage and Click a Button Intstead

Mindwatering Incorporated

Author: Tripp W Black

Created: 01/01/2012 at 07:04 PM

 

Category:
Notes Developer Tips
XPages

Issue:
Have single edit box on section of XPage not bound to a data source (think search type field and button). I want to enter something in the field and be able to hit the enter button. When the enter button is clicked, I don't want the browser to do it normal submission, but instead click the button next door. You cannot use the standard event kb handler (in this support reference app) as the XPage's Dojo seems to use it's own events. So instead you need the following solution.

Solution:
Add the following:
Events --> Key --> onkeydown --> Client --> Execute Script

if (thisEvent.keyCode==13) {
thisEvent.preventDefault();
var btnm = '#{id:btnMyButton1}';
var btnobj = document.getElementById(btnm);
if (btnobj != null) {
btnobj.click();
}
}

The key is the thisEvent.preventDefault() line. It's stops the 13 from taking place. To click the button, I simply get it by name using the #{} ID wrapper function and use its click action as normal.



previous page