XPages - onkeypress event does not fire correctly

I created a search field (id: searchField) and a search button (id: searchButton) using Xpages user controls. I added the onkeypress event to the search field so that it triggered a click on searchButton. Then, SearchButton will reload the page, but with the url parameters coming from the search field. The problem is that the page reloads, but the search parameters are not added to the URL when I press ENTER in the search field , but it works correctly when I click the search button. Here are the codes I used:

(code added to onkeypress searchField)

if (typeof thisEvent == 'undefined' && window.event) {thisEvent = window.event; }
if (thisEvent.keyCode == 13)
{
    document.getElementById ("# {id: searchButton}"). click ();
}

(code added to onclick searchButton)

window.location.href = "test.xsp? search =" + document.getElementById ("# {id: searchField}"). value;

I tested it in IE and Firefox, both have problems. I created a sample HTML file and it worked correctly. Is this an XPages error, or am I missing something?

+5
source share
4 answers

Add this after your .click () ':

       thisEvent.preventDefault();
       thisEvent.stopPropagation(); 

He must solve the problem; -)

+7
source

Change the onKeyPress event of the input field to

if (typeof thisEvent == 'undefined' && window.event) { thisEvent = window.event; }
if (thisEvent.keyCode == dojo.keys.ENTER)
{
    dojo.byId("#{id:searchButton}").click();
    thisEvent.preventDefault();
}

should be enough to solve the problem. Please note that for compatibility with multiple browsers I used

dojo.keys.ENTER

and

dojo.byId("id");

/. dojo.keys : .

+6

I did this most recently in XPage, and the following script works for me in a cross browser:

var e = arguments[0] || window.event;
if ( e.keyCode==13 || e.which==13) {
  window.location.href = 'searchResults.xsp?query=' + 
      encodeURI(dojo.byId('#{id:searchInput}').value));
  return false;
}

Hope this helps,

Jeremiah

0
source

The problem with the id generated by xpage. I had the same problem. xPages prefix of the identifier of the custom control, for example view: _id1: _id ... Try to specify the full id

0
source

All Articles