You need to sign in to do that
Don't have an account?

actionSupport selectOptions
my controller is pulling a list of app names(which are picklist values on a custom field) and displaying it on the page. Now the picklist values show as checkboxes fine but when I select Cool App 1 check box on the page, the input field doesn't show.....perhaps I need a getter or setter on the selectedApp in the controller?
public List<SelectOption> getApps(){
if(apps== null){
apps= new List<SelectOption>();
Schema.DescribeFieldResult appField = Schema.sObjectType.Lead.fields.Applications__c;
Schema.PicklistEntry [] values = appField.getPickListValues();
for(Schema.PicklistEntry value: values){
apps.add(new SelectOption(value.getValue(), value.getLabel()));
}
}
return apps;
}
<apex:panelGrid columns="2">
<apex:outputLabel for="apps"><span class="required">* </span>My Apps:</apex:outputLabel>
<apex:outputPanel >
<apex:actionRegion >
<apex:selectCheckBoxes value="{!selectedApps}" required="true">
<apex:selectOptions value="{!apps}"/>
<apex:actionSupport event="onchange" rerender="appTypeDiv"/>
</apex:selectCheckBoxes>
</apex:actionRegion>
</apex:outputPanel>
</apex:panelGrid>
<apex:panelGrid columns="2">
<!-- input field code for Cool App2-->
<!-- input field code for Cool App3-->
<apex:outputPanel id="appTypeDiv" rendered="{!apps= 'Cool App 1'}">
<apex:outputLabel for="appType"><span class="required">* </span> App Type:</apex:outputLabel>
<apex:inputField value="{!Lead.App_Type__c}" id="appType" required="true"/>
</apex:outputPanel>
</apex:panelGrid>
You can do like this. do the rendered and rerender in separate outputpanel as it will not work in the same.
<apex:panelGrid columns="2">
<apex:outputLabel for="apps"><span class="required">* </span>My Apps:</apex:outputLabel>
<apex:outputPanel >
<apex:actionRegion >
<apex:selectCheckBoxes value="{!selectedApps}" required="true">
<apex:selectOptions value="{!apps}"/>
<apex:actionSupport event="onchange" rerender="appTypeDiv"/>
</apex:selectCheckBoxes>
</apex:actionRegion>
</apex:outputPanel>
</apex:panelGrid>
<apex:panelGrid columns="2">
<!-- input field code for Cool App2-->
<!-- input field code for Cool App3-->
<apex:outputPanel id="appTypeDiv" >
<apex:outputPanel rendered="{!products = 'Cool App 1'}">
<apex:outputLabel for="appType"><span class="required">* </span> App Type:</apex:outputLabel>
<apex:inputField value="{!Lead.App_Type__c}" id="appType" required="true"/>
</apex:outputPanel>
</apex:outputPanel>
</apex:panelGrid>
And also in the controller make selectedApp {get;set;}
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Well just adding few info why its not working!
In VF you cannot rerender a component which is not visible(rendered ="false") in page. Initially "appTypeDiv" is not visible because the condition doesnt match, SO to make this component visible we will have to rerender the parent component(which is visible). In our case its the "panelGrid"
So the code should be
Ok ..my code didn't work but there is just too much to show here so here is a similar example that is same conceot from the sfdc docs but how come my <apex:outputText doesn't display after I select US checkbox? i think if i can get this to work i can do the same type of logic to my other code
public class sampleCon {
public String[] countries{get;set;}
public PageReference test() {
return null;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));
return options;
}
}
<apex:page controller="sampleCon">
<apex:form >
<apex:actionRegion >
<apex:selectCheckboxes value="{!countries}">
<apex:selectOptions value="{!items}"/>
<apex:actionSupport event="onchange" reRender="myDiv"/>
</apex:selectCheckboxes><br/>
</apex:actionRegion>
</apex:form>
<apex:outputPanel id="myDiv">
<apex:outputPanel rendered="{!countries= 'US'}">
<apex:outputText value="The unformatted time right now is: {!NOW()}" />
</apex:outputPanel>
</apex:outputPanel>
</apex:page>
I wil try this but the thing is, i only want to show or hide this field below if one of the checkboxes is selected but the 2 other fields should always display. In that case, how should i do it since th panel grid is still there
also can you see the code in the country example..that one will be easier
Perhaps because if i select the checkbox it returns a boolean and not a string?
Well wrongly used the operator here
It should be
still didn't work - here is the exact code - u can paste it into your browser. When US is selected it should show the output text automatically and whern it is unselected, it should hide the output text. If any other countries are selected then it should still show the output text as log as US is still selected
<apex:page controller="sampleCon">
<apex:form >
<apex:actionRegion >
<apex:selectCheckboxes value="{!countries}">
<apex:selectOptions value="{!items}"/>
<apex:actionSupport event="onchange" reRender="myDiv"/>
</apex:selectCheckboxes><br/>
</apex:actionRegion>
</apex:form>
<apex:outputPanel id="myDiv">
<apex:outputPanel rendered="{!countries== 'US'}">
<apex:outputText value="The unformatted time right now is: {!NOW()}" />
</apex:outputPanel>
</apex:outputPanel>
</apex:page>
public class sampleCon {
public String[] countries{get;set;}
public PageReference test() {
return null;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));
return options;
}
}
Countries should be string and not an array