0

I'm trying to create a FAQ section on my Force.com site that queries our org's Solution object and dynamically display Solution titles as links via commandLinks. I want to display a pop up modal that presents the Solution record's contents via javascript and CSS.

I created an openMod() javascript function to do just that. However, I that when the button is clicked, it initiates the modal, then submits the page as a form.

Is it possible to disable the form submission from my commandLink? I've look at other markups such as outputLink, but I wasn't able to prevent the default events. I just want my link to initiate JS code with SFDC variables passed in.

Thanks!!

<apex:repeat value="{!solution}" var="sol" >
   <p>
      <apex:commandLink onclick = "openMod('{!sol.SolutionName}', '{!sol.SolutionNote}')" value="{!sol.SolutionName}"/>
   </p>  
</apex:repeat>
  • Try Adding "return false;" to commandLink onClick attribute. – javanoob Jan 31 '17 at 2:00
3

here is a page you can use to test the various iterations:

<apex:page>

<apex:form>
<!-- Causes Form Submission Issue -->
<apex:commandLink onclick = "alert('hi');" value="without rerender"/>
<br />

<!-- DOES NOT Causes Form Submission Issue -->
<apex:commandLink onclick = "alert('hi');" value="With Rerender" reRender="none"/>
<br />

<!-- Causes Form Submission Issue -->
<apex:commandLink onclick = "alert('hi');" value="With Immediate" immediate="true"/>
<br />

<!-- DOES NOT Causes Form Submission Issue -->
<apex:commandLink onclick = "alert('hi'); return false;" value="return false"/>
<br />
</apex:form>

</apex:page>

Of note, the two that work are:

  1. With Rerender (As long as there is some text in the rerender, even if not matching any element id)
  2. Return false

The other two cause a form submission.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.