You need to sign in to do that
Don't have an account?
kenzo
Status Query: Radio Buttons
Hey - Newbie Q: I found postings from '07 indicating SFDC doesn't support Radio Buttons, but instead allows for PickList functionality only in Custom Objects.
Just want to verify that this is still the case.
I found code for creating Radio Buttons on a page, but I'm assuming there is no way to connect the User's selection to a Custom Field in a Custom Object. Correct?
Trying to avoid the visual design of many, many drop-down boxes.
Any status updates will be appreciated. Thanks.
You are on the right track. You basically have two options.
1) Hard code the select option values. If you know these values will never change this may be the best option as no apex is required but is not dynamic and if new values are added to the picklist the page will need to be updated.
<apex:page standardController="Account">
<apex:form>
<apex:selectRadio value="{!Account.Ownership}">
<apex:selectOption itemLabel="Public" itemValue="Public"/>
<apex:selectOption itemLabel="Private" itemValue="Private"/>
<apex:selectOption itemLabel="Subsidiary" itemValue="Subsidiary"/>
<apex:selectOption itemLabel="Other" itemValue="Other"/>
</apex:selectRadio>
</apex:form>
</apex:page>
2) Use apex to inspect the schema and dynamically build the list of selection option. Pro: it scales,Con (maybe?) is that it requires apex.
PAGE:
<apex:page standardController="Account" extensions="radioOptions">
<apex:form>
<apex:selectRadio value="{!Account.Ownership}">
<apex:selectOptions value="{!ownershipValues}"/>
</apex:selectRadio>
</apex:form>
</apex:page>
EXTENSION:
public class radioOptions {
List<SelectOption> ownershipValues;
public radioOptions(ApexPages.StandardController controller){}
public List<SelectOption> getOwnershipValues(){
if(ownershipvalues == null){
ownershipValues = new List<SelectOption>();
for(Schema.PicklistEntry p : Account.Ownership.getDescribe().getPicklistValues()){
if(p.isActive() == true){
ownershipValues.add(new SelectOption(p.getValue(),p.getLabel()));
}
}
}
return ownershipValues;
}
}
Hope that helps.
-Jason
All Answers
If you are creating a visualforce page you can basically convert a picklist field into a radio button selection. Is this what you are trying to do?
TehNrd: I believe so (still learning the ropes here). Do you have a simple sample of how to perform this picklist to radio button selection conversion? Appreciate any help you can offer. Some sample lines that I hope you can guide me on are below:
<p>1. After your request for quotation, rate the promptness of your sales representative’s feedback?</p>
//Below is the picklist version that will come up with a 1-5 (+None) selection
<apex:inputField value="{!Warranty__c.Promptness__c}"/>
//Below is the code someone provided (another thread) for creating radio buttons (without any tie in to the form, though)
<apex:selectRadio >
<apex:selectOption itemValue="1" itemLabel="1" />
<apex:selectOption itemValue="2" itemLabel="2" />
<apex:selectOption itemValue="3" itemLabel="3" />
<apex:selectOption itemValue="4" itemLabel="4" />
<apex:selectOption itemValue="5" itemLabel="5" />
</apex:selectRadio>
Not sure if these sample lines helped shed some light, but hopefully...
You are on the right track. You basically have two options.
1) Hard code the select option values. If you know these values will never change this may be the best option as no apex is required but is not dynamic and if new values are added to the picklist the page will need to be updated.
<apex:page standardController="Account">
<apex:form>
<apex:selectRadio value="{!Account.Ownership}">
<apex:selectOption itemLabel="Public" itemValue="Public"/>
<apex:selectOption itemLabel="Private" itemValue="Private"/>
<apex:selectOption itemLabel="Subsidiary" itemValue="Subsidiary"/>
<apex:selectOption itemLabel="Other" itemValue="Other"/>
</apex:selectRadio>
</apex:form>
</apex:page>
2) Use apex to inspect the schema and dynamically build the list of selection option. Pro: it scales,Con (maybe?) is that it requires apex.
PAGE:
<apex:page standardController="Account" extensions="radioOptions">
<apex:form>
<apex:selectRadio value="{!Account.Ownership}">
<apex:selectOptions value="{!ownershipValues}"/>
</apex:selectRadio>
</apex:form>
</apex:page>
EXTENSION:
public class radioOptions {
List<SelectOption> ownershipValues;
public radioOptions(ApexPages.StandardController controller){}
public List<SelectOption> getOwnershipValues(){
if(ownershipvalues == null){
ownershipValues = new List<SelectOption>();
for(Schema.PicklistEntry p : Account.Ownership.getDescribe().getPicklistValues()){
if(p.isActive() == true){
ownershipValues.add(new SelectOption(p.getValue(),p.getLabel()));
}
}
}
return ownershipValues;
}
}
Hope that helps.
-Jason