+ Start a Discussion
Baird_SBaird_S 

Easier option than selectradio or selectlist?

I'm creating a survey, and want to have respondents answer picklist questions using radio buttons.

 

I can do this using the standard selectradio, selectoptions approach.

 

But this requires me to specify the values of the options anew for every question.  With 40 questions that's a lot of coding, although it can be simplified using maps.  But before I dig into that ...

 

Is there an existing jquery or other pre-made javascript function which takes a salesforce picklist field and transforms it from its standard dropdown format into radio buttons, and includes all the values from the picklist field, without having to program those values into it using selectoptions?

 

Thanks in advance, Baird

sfdcfoxsfdcfox

No need to explictly build the list yourself:

public SelectOption[] getOptionList() {
  SelectOption[] values = new SelectOption[0];
  for(picklistentry ple:schema.account.fields.industry.getdescribe().getpicklistvalues()) {
    values.add(new selectoption(ple.getvalue(), ple.getlabel());
  }
  return values;
}

Bind this function to a apex:selectOptions, and you're done. You can even have it dynamically choose the field(s) to obtain the picklists for, and, of course, changing the setup automatically updates your page's values.

Baird_SBaird_S

Thanks, sfdcfox.  That helps.