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
wesnoltewesnolte 

Pressing enter on form with commandlink doesn't submit form

Hello

 

I have a form that contains an inputtext and a commandlink that submits the form when clicked. I have noticed that if I press the enter key after entering text in the inputtext the page just refreshes. If I change the commandLink to a commandButton the form does submit, but I have certain reasons for using commandLink, so this is not feasible.

 

I have noticed this behaviour in another form on a seperate page too. Any ideas?

 

Wes 

Rajesh ShahRajesh Shah
Does your commandLink have rerender attribute? Check the html code that is generated. I had the same problem with commandButton. I checked the html code that was generated. When there was no rerender attribute, the button type generated in html was of 'Submit'. In this case, enter worked. But when I had rerender attribute, the button type generated in html was of plain 'button'. In this case, enter didn't worked. Hope this helps
wesnoltewesnolte

I should have posted some code hey;)

 

                <apex:form id="seachForm">
                    <apex:inputText id="sInput" value="{!keywords}" />
                    <apex:commandLink target="_top" id="sBtn" value="Search" action="{!search}"/>
                </apex:form>

 

Thanks for the suggestion but there isn't a rerender. I tried to use some javascript to simulate the behaviour ie. an onkeypressed even on the inputText that checked for key 13, but that was being a bit weird.

 

The HTML that is rendered is doesn't contain any type of buttons at all. But after following your advice and having a look  at  HTML I can see that they're using javascript to submit the form with the commandlink is clicked.

 

I think I may have to log a bug case.

thangasan@yahoothangasan@yahoo

Hai

 

   Sample Program for command Link submit

 

  

<apex:page controller="TestBtnLinkController">

<apex:form >
<apex:pageBlock mode="edit" id="block">
<apex:pageBlockSection >
<apex:inputText id="sInput" value="{!inputValue}" />
<apex:commandLink value="Go Link" action="{!passParam}" >
</apex:commandLink>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>
public class TestBtnLinkController{
    String inputValue;
    
    public TestBtnLinkController(){
      }
    
    
    public String getInputValue(){
        return inputValue;
    }
    
    public void setInputValue(String inputValue){
        this.inputValue = inputValue;
    }
    
    public void passParam(){
        System.debug('inputValue  :'+ this.inputValue );
    }
}

Regards

Thanga

wesnoltewesnolte

Computer says no.

 

I'm afraid this will not work. What I need is for the action method to return a pagereference when I press the enter key. Change your class like this and instead of clicking the link press enter when done typing,

 

public class TestBtnLinkController{
    String inputValue;
   
    public TestBtnLinkController(){
      }
   
   
    public String getInputValue(){
        return inputValue;
    }
   
    public void setInputValue(String inputValue){
        this.inputValue = inputValue;
    }
   
    public PageReference passParam(){
        System.debug('inputValue  :'+ this.inputValue );
        return System.Page.Home;
    }
}

 

The page will refresh. Now try changing the commandlink to a button and it works.

 

Thanks for the effort though,

Wes

wesnoltewesnolte

Hey

 

I've logged a Case 02831282. If anyone knows any tricks in the meantime feel free to post as some times resolution on cases can be, um.. tardy.

 

Wes

 

 

Rajesh ShahRajesh Shah
When you used javascript to check if the enter was pressed, did you also did form.submit()? I know its a stupid question but still just for confirmation.
wesnoltewesnolte
yeah, just refreshes :(
LinvioIncLinvioInc

I've found that if you omit the rerender parameter on an apex:commandButton tag, Salesforce will post the form.  Otherwise, apex:commandButton and apex:commandLink will just invoke an ajax call to your action function.

 

If you need to run javascript form validation before calling your action function, just call it from the apex:commandLink onclick parm:

 

<apex:commandLink id="payPalButton"  
 	action="{!paypalPurchase}"
 	status="formActionStatus" 
   	onclick="enableValidation=true;return validateForm();">
     	<apex:image id="payPalBuyNowButtonImage" style="vertical-align:middle;" url="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" />
</apex:commandLink>