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>
1
  • Try Adding "return false;" to commandLink onClick attribute.
    – javanoob
    Jan 31, 2017 at 2:00

1 Answer 1

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.

0

You must log in to answer this question.

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