XPages - onkeypress event not triggering click properly

烂漫一生 提交于 2019-12-05 10:26:45

Add this after your '.click()':

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

It should solve the problem ;-)

Changing 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 sufficient to solve the problem. Note that for cross browser compatibility I've used the

dojo.keys.ENTER

and

dojo.byId("id");

property/ method. The dojo.keys object has a lot more properties to check for certain key presses: see here

Mark

I've done this just recently in an XPage, and the following script works for me 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,

Jeremy

Issue is there with the id, generated by xpage. I had a same issue. xPages prefix the id of custom control like view:_id1:_id... Try by giving complete id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!