function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ken KoellnerKen Koellner 

Enter key on apex:InputText causing submit of command button

I have an apex:InputText field.  Hitting Enter in the field causes the next CommandButton on the page to be executed.  I do not what that to happen.  The commandButton is not even the next element on the page.  I have several inputText entries.  If I hit enter in the first one, the next CommandButton on the page is executed.

 

Anyone know if there's a way to defeat that functionality?

 

I see documentation on the "accessKey" attribute on commandButton but no details.  I don't have that specified and don't know if specifying anything here could cause the functionality to be defeated.

 

Any ideas?

 

There's one case in my application where hitting Enter and executing the next CommandButton on the page would make sense.  Everywhere else it does not.  I really want to turn that functionality off in those cases.

ColinKenworthy2ColinKenworthy2

Enter this script in your page :

<script> 
function ignoreEnterKey(e){
    if ((window.event&&window.event.keyCode==13) || e.which==13) {
        return false;
    } else {
        return true;
    };
} 
</script>

 

and then in your inputText field have an onKeyUp attribute like this :

    <apex:inputText id="?????" value="{!???????????}" onkeyup="ignoreEnterKey(event);"/>