function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
HalcyonandonHalcyonandon 

Form submit, dependent picklists

I followed the example provided at http://wiki.apexdevnet.com/index.php/Extended_Functionality_of_Visualforce_-_Part_2 to create dynamic picklists on a form for entering information.  The idea behind the form is that the user will select a group from a picklist.  The chosen group generates the categories related to it.  This works beautifully, unfortunately the tutorial cut off before going into more detail on working with dependent pick lists.  The main point of the form is so the user can enter in topics and directions.  This also works, however in addition to submitting data to those fields in the custom object, their selected category also needs to be submitted to the category field (which has a lookup relationship to the category custom object).

here's my visualforce page code...

<apex:page showheader="true" standardcontroller="Topic__c" extensions="helpFormController" id="UseCaseDisplay" label="TopicCategoryReport" >

<apex:form>


<apex:outputLabel value="Grouping:" for="grouping"/>
<apex:selectList value="{!grouping}" size="1" id="grouping">

<apex:selectOptions value="{!groupings}"/>
<apex:actionSupport event="onchange" rerender="categories"/>
</apex:selectList>
<a class="title" href="/apex/addgrouping" target="_blank">New</a>
<br /> <br />

<apex:outputLabel value="Category:" for="categories"/>
<apex:selectList value="{!Category}" size="1" id="categories" disabled="{!ISNULL(grouping)}">
<apex:selectOptions value="{!Categories}"/>
</apex:selectList>
<a class="title" href="/apex/addcategory" target="_blank">New</a>
<br /> <br />
<h2>New Topic: </h2>
<apex:inputField value="{!Topic__c.name}" id="topic"/><br /><br />
<h2>Directions: </h2><br />
<apex:inputtextarea id="directions" cols="100" rows="25" value="{!Topic__c.Directions__c}"/> <br /><br />
<apex:commandButton value="Save" action="{!Save}" onClick="beforeTextSave()"/>
</apex:form>
</apex:page>

And here is the controller extension code...

public class helpFormController {

public helpFormController (ApexPages.StandardController stdController){

}
/* String value for the grouping */
String grouping;

/* String value for the category */
String category;

/* Getter for the grouping value */
public String getGrouping() { return this.grouping; }

/* Setter for the grouping value */
public void setGrouping(String s) { this.grouping = s; }

/* Getter for the category value */
public String getCategory() { return this.category; }

/* Setter for the category value */
public void setCategory(String s) { this.category = s; }

/* Getter which dynamically generates the groupings from the Grouping__c object. */
public List<SelectOption> getGroupings() {
List<SelectOption> optionList = new List<SelectOption>();
/* Add a null option to force the user to make a selection. */
optionList.add(new SelectOption('','- None -'));

/* Loop through the feature_category__c records creating a selectOption
for each result with the record ID as the value and the name as the label
displayed in the selectList */

for (Grouping__c fc: [select name from Grouping__c order by Name]){
optionList.add(new SelectOption(fc.id,fc.name));
}
return optionList;
}
/* Getter which generates the options for the Topic selectList based on the current
value of the selected category. If there is no value selected then only
the null option should be returned. */


public List<SelectOption> getCategories() {
List<SelectOption> optionList = new List<SelectOption>();
/* Add a null option to force the user to make a selection. */
optionList.add(new SelectOption('', '- None -'));

/* If a category has been selected then query for the related values */
if(grouping!= NULL) {

/* Loop over the related feature records for the given category
creating a selectOption with the value being the feature record ID
and the label is the name of the feature. */

for (Category__c f : [select name from Category__c f where f.Grouping__c = :grouping]){
optionList.add(new SelectOption(f.name,f.name));
}
}
return optionList;
}
}

Ron HessRon Hess
> This also works, however in addition to submitting data to those fields in the custom object, their selected category also needs to be
> submitted to the category field (which has a lookup relationship to the category custom object).


I think you can just use an input field , with a value of the relationship ID field of the category custom object, Visualforce will draw the relationship picker for you, and the standard controller will save that value.

<apex:inputfield value={!Topic__c.ParentId}" >



Message Edited by Ron Hess on 04-18-2008 07:00 PM
HalcyonandonHalcyonandon
Hey,

Thanks for the help.  This works well for saving the category to the topic.  The issue is that doing it like this allows the user to select any category without reference to the grouping above it.  We're going to have a large number of categories, so we need to break it down by groupings first.


jarrodmichaeljarrodmichael

Any luck on this?  I would like to do the very same thing