[SalesForce] unable to rerender inputfield

I am trying to rerender an input field based on the event 'onchange' specific other input field which is of type multiselect picklist.

vf page

<apex:inputField value="{!MyObject__c.myField__c}">
<apex:actionSupport action="{!myMethod}" rerender="idToRender" event="onchange"/>
</apex:inputField>
<apex:inputField id="idToRender" value="{!MyObject__c.toBeRenderedField__c}" rendered="{!myBool}"/>

apex class

myMethod()
{
myBool = true;
}

Best Answer

<apex:inputField id="idToRender" value="{!MyObject__c.toBeRenderedField__c}" rendered="{!myBool}"/>

Instead of this you need to do this

<apex:outputpanel  id="idToRender">
<apex:inputField value="{!MyObject__c.toBeRenderedField__c}" rendered="{!myBool}"/>

</apex:outputpanel >

Because when first time page load this inputfield is rendered= false so it is not available on page so you can't rerender it. In that case we need to rerender the parent component.

Related Topic