Display fields based on selection in selection selection

I have a VF page where I am using apex: pageblocktable to display a group of posts. One of the columns is a selector and I need to display / not display the fields according to the selection in the select list.

 <apex:pageBlockTable value="{!showRecord}" var="item">
  <apex:column headerValue="Delivery">
    <apex:inputField value="{!item.delivery__c}"/>
  </apex:column>
  <apex:column headerValue="Roadway">
    <apex:inputField value="{!item.road__c}"/>
  </apex:column>
  <apex:column headerValue="Rail">
    <apex:inputField value="{!item.rail__c}"/>
  </apex:column>
 </apex:pageBlockTable>

      

in the above code, delivery_c is a picker with the values ​​of roads and railways. if user selects road tracks then i need to display road - c and if user selects railways then i need to display rail_c

How can i do this?

thank

+3


source to share


1 answer


One way to do this is by using Partial Page Updates in Visualforce.

Put both fields in the same column and use the "rendered" attribute to dynamically show / hide the field using an if-statement. Then you set up the AJAX onchange event handler for the delivery__c field using the actionSupport tag. This will basically listen to that field for change and then update the table on the page. Each time this update is updated, your if statements will be reevaluated and result in one of the two fields in that column being displayed.



I haven't had a chance to try this, but I think it should work.

<apex:pageBlockTable id="mytable" value="{!showRecord}" var="item">
  <apex:column headerValue="Delivery">
    <apex:actionRegion>        
      <apex:inputField value="{!item.delivery__c}">
        <apex:actionSupport event="onchange" reRender="mytable">
      </apex:inputField>
    </apex:actionRegion>
  </apex:column>
  <apex:column headerValue="Delivery Type">
    <apex:inputField rendered="{!item.delivery__c='Road'}" value="{!item.road__c}"/>
    <apex:inputField rendered="{!item.delivery__c='Rail'}" value="{!item.rail__c}"/>
  </apex:column>
</apex:pageBlockTable>

      

+3


source







All Articles