3

Overriding activity page for some objects. So we set up visual force page accordingly.

Everything is working fine but I need when the rep clicks the Enter key automatically specific button called "No" needs to fire. But when I enter automatically save button is committed to the database.

This button needs to fire:

<apex:commandButton id="searchButton" value="No" action="{!closePopup}" rerender="tstpopup" />

I tried multiple ways. But nothing is working where I missed it

I took reference from following links:

http://bobbuzzard.blogspot.com/2012/10/press-enter-to-submit.html

https://developer.secure.force.com/cookbook/recipe/submit-a-form-with-the-enter-key Vf Code:

<apex:page standardController="Task" extensions="LogACallControllerExtension">
  <apex:sectionHeader title="Log a Call" />
  <apex:form id="pageForm">
  <apex:pageBlock title="Task Edit" mode="edit">
  <apex:pageBlockButtons location="top">
  <apex:commandButton value="Save" action="{!save}"/>
  <apex:commandButton value="Cancel" action="{!cancel}" />
  </apex:pageBlockButtons>
  <apex:pageBlockSection title="Call Information" columns="2" collapsible="false">
  <apex:inputField value="{!Task.OwnerId}"/>
  <apex:outputField value="{!Task.WhatId}"/>
  <apex:inputField value="{!Task.Subject}"/>
  <apex:Outputfield value="{!Task.Status}"></apex:Outputfield>
  <apex:inputField value="{!Task.ActivityDate}"/>
  <apex:inputfield value="{!Task.Activity_Type__c}" required="true"/>
   <apex:inputfield value="{!Task.Description}" style="width:400px;height:100px;"/>
  </apex:pageBlockSection>
  <apex:panelGrid columns="3" style="margin: 0 auto;">
  <apex:outputLabel >Reminder</apex:outputLabel>
  <apex:inputField value="{!Task.IsReminderSet}"/>
  <apex:inputField value="{!Task.ReminderDateTime}"/>
  </apex:panelGrid>
  </apex:pageBlockSectionItem>
  </apex:pageBlockSection>
  </apex:pageBlock>
  <apex:outputPanel id="tstpopup">
        <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>
            <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
              <apex:panelgrid columns="1" style="margin: 0 auto;">
              Was this a connect with Decision Maker/Influencer 
              </apex:panelgrid>
              <apex:panelgrid columns="2" style="margin: 0 auto;" id="inside" >
              <apex:commandButton value="Yes" action="{!saveconnect}" rerender="tstpopup"/>
                <apex:commandButton id="searchButton" value="No" action="{!closePopup}" rerender="tstpopup" />
              </apex:panelgrid> 
            </apex:outputPanel>
        </apex:outputPanel>
</apex:form>
</apex:page>
3
  • can you specify the "multiple ways" you tried?
    – glls
    Jul 26, 2018 at 14:15
  • I updated my references in the question
    – Pavan tej
    Jul 26, 2018 at 14:57
  • Do you want to close the popup window ? when you are clicking on "No" button on popup? Can you please share the apex code what you have written on "closePopup" method? Also, can you please tell me when you click on "No" button whether its invoking "closePopup" method or not. Did you kept debug log for this? Aug 6, 2018 at 6:42

2 Answers 2

4
+25

I do not see any JS code on your page which is outlined in the reference you linked to and said you used so I am not sure how much more help this will be since it is essentially restating what was in your references.

This is essentially a duplicate of this question.

  • Create an action function that is called by the button and can be called from JS

    <apex:actionFunction name="closePopUp" 
         action="{!closePopup}" rerender="tstpopup"/>
    
  • Trap the enter key using a document.keypress event calling below on key press and call the action function if enter was the key pressed

    <script type='text/javascript'>
    function noenter(ev)  {
        if (window.event && window.event.keyCode == 13 || ev.which == 13) {
            closePopUp();
            return false;
         } else {
              return true;
         }
     }
    </script>
    

And change your command button to:

<button type="button" id="searchButton" value="No" onclick="return closePopUp();" />
1
  • Still it is firing save button automatically.
    – Pavan tej
    Jul 31, 2018 at 13:30
1

We had a similar problem.
When the page is rendered, the browser automatically assigns the Enter key to the first button it encounters. So what we did was to put an invisible button on the top of the page to call the action that we want to apply to the Enter key. No fuss, no muss, no Javascript.

<apex:page standardController="Task" extensions="LogACallControllerExtension">
  <apex:sectionHeader title="Log a Call" />
  <apex:form id="pageForm">
    <apex:pageBlock title="Task Edit" mode="edit">
      <apex:pageBlockButtons location="top">
        <apex:commandButton id="searchButton" value="No" action="{!closePopup}" rerender="tstpopup" style="display:none"/>
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}" />
      </apex:pageBlockButtons>
      <apex:pageBlockSection title="Call Information" columns="2" collapsible="false">
      ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .