I'm trying to pass through some additional information via the html- passthrough on apex:selectoptions from the controller.

Ie I need it to output:

<apex:selectOption html-data-range="h" itemValue="RW" itemLabel="Running" />

because I use the data attribute to change some front-end stuff.

is there any way to set the html-passthrough value from the controller?

  • 1
    Unfortunately, SelectOption is a final class, and doesn't have any way to express additional values beyond "value" and "label." The only clear workaround I can think of would be to use normal HTML constructs (e.g. emit a normal select with option children) by using a wrapper class to expose the passthrough parameters (at which point, they're just normal HTML attributes, don't include the html-). Then, wire up an onchange JavaScript event that would populate a backing field (e.g. <apex:inputHidden value="{!selectedOptions}" id="mySelectionValues" />. Let's see if anyone has an idea. – sfdcfox Mar 27 '15 at 20:57
  • that's a pretty good idea. My other workaround thought would be to also just dump the fields to the page via a serialized JSON object and then have the frontend pull the extra values out by looking up the selected value. – Simon Jensen Mar 27 '15 at 21:04
  • JSON serialization will work. I have tried previously in some use cases to render dropdowns. You can serialize JSON and assign to a string property in controller, it will be available in javascript in page. – Victor Mar 28 '15 at 6:48
  • I would think writing your own CustomSelectOption wrapper would be the simplest solution. You would need to use the html select tag but no JavaScript. – Adrian Larson Mar 30 '15 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.