1

I created a form and I want to show the checkbox option depending on the value in the picklist. Let's say if the user chooses "Apples" in the picklist, the checkbox shows, if he choooses "Oranges" the checkbox stays hidden. How would I do this?

I am new to this whole platform and apex in general, please be kind and thank you for you answers.

Code:

<apex:page StandardController="tudent__c">
<apex:form >

    <apex:pageBlock title="Prijava Študenta">


    <apex:actionRegion >   
    <apex:pageBlockSection columns="1" id="formToRerender">

        <apex:actionSupport event="onchange" reRender="formToRerender"/>

        <apex:inputField value="{! tudent__c.Name }"/>
        <apex:inputField value="{! tudent__c.Priimek__c }"/>        
        <apex:inputField value="{! tudent__c.Naslov__c }"/>        
        <apex:inputField value="{! tudent__c.Datum_Rojstva__c }"/>
        <apex:inputField value="{! tudent__c.Letnik__c }"/>   
        <apex:inputField value="{! tudent__c.Studijski_program__c }"/> 
        <apex:inputField value="{! tudent__c.Samopla_niki__c }" rendered="{!tudent__c.Studijski_program__c='Izredni'}"/>  

    </apex:pageBlockSection>
    </apex:actionRegion>   


    <apex:pageBlockButtons >
        <apex:commandButton action="{! save }" value="Save" />        
    </apex:pageBlockButtons>

</apex:pageBlock>

     <apex:pageBlock title="Študenti">

<apex:pageBlockTable value="{!tudent__c}" var="contact">



    <apex:column value="{!contact.Name}"/>
    <apex:column value="{!contact.Priimek__c}"/>
    <apex:column value="{!contact.Naslov__c}"/>
    <apex:column value="{!contact.Datum_rojstva__c}"/>
    <apex:column value="{!contact.Studijski_program__c}"/>
    <apex:column value="{!contact.Samopla_niki__c}"/>


</apex:pageBlockTable>
</apex:pageBlock>



</apex:form>
</apex:page>
  • Your table is using a single sObject. What is the purpose since you show the information in the pageblock section. Either way use the render attribute and the value bound to the picklist. Rerender table on change of picklist – Eric Sep 17 '16 at 12:31
  • Yes and you use the value the picklist is bound to – Eric Sep 17 '16 at 13:01
  • See answer here salesforce.stackexchange.com/questions/140671/… – Eric Sep 17 '16 at 13:13
  • What's going on with your questions, why are you censoring them? – smukov Sep 22 '16 at 7:36
  • For some reason it won't let me change my email so I wanted to delete my account and make a new one. I'm sorry for the confusion, I contacted the help center. – Xxx Sep 22 '16 at 7:51
3

Below you can see a simple example that doesn't require the use of custom controller or controller extensions, so you can keep using just your standardController as you already are. You should be able to implement a similar logic for your page.

<apex:page standardController="Account" >  
    <apex:form >
         <apex:pageBlock title="New Account" >

             <apex:actionRegion> 
                 <apex:pageBlockSection id="pbToRerender">                
                        <apex:inputField value="{!Account.Type}" >
                            <apex:actionSupport event="onchange"                             
                                                rerender="pbToRerender"/>
                        </apex:inputField>    
                        <apex:inputField value="{!Account.AccountNumber}" rendered="{!Account.Type='Prospect'}">
                        </apex:inputField>          
                 </apex:pageBlockSection>
             </apex:actionRegion>

             <apex:pageBlockSection >
                 <apex:inputField value="{!Account.Name}"></apex:inputField>
             </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Basically, when you change the Account.Type the onchange event will be triggered, causing the re-rendering of the pageBlockSection. The actionRegion tag will make sure that only this limited part of the page is submitted and processed on the server. In the example above it allows the user to change the picklist without the need to input the Account.Name, which is a required field.

However, if you want to do this "client-side" only, you can use JQuery to show/hide your checkbox when the picklist changes.

  • Update your code above please, so we can see what code you have now. – smukov Sep 17 '16 at 15:28
  • See my example code again, the actionSupport needs to be between the inputField tags so it gets triggered when that inputField changes. Try like this: <apex:inputField value="{! tudent__c.Studijski_program__c }"> <apex:actionSupport event="onchange" reRender="formToRerender"/></apex:inputField> – smukov Sep 17 '16 at 15:31
  • It's not that hard, you'll get a hang of it in a few weeks, I'm sure. BTW, just curious, what's the language that you are using in your form? It looks very similar to Serbian, but not quite the same :) – smukov Sep 17 '16 at 15:38
  • I think you should ask a separate questions for this new problem you are facing so that you can get a detailed answer. However, this might get you started: developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/… – smukov Sep 17 '16 at 17:12

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.