Depending on your question form's complexity, it could be challenging to use an <apex:inputField />
tag.
Assuming the custom object you refer to with the field on it of AnswerType
is the Question
, you could use something like this in the VF page to handle each type of display output you intend to support.
In this model, each Question
record has the text of the question and the DisplayType__c
for driving the UI element shown to gather the response. The Answer
record is very simple and just has a Long Text Area field on it that captures any answer type in the exact same field, as plain text.
Note: items not shown - getting the list of questions, storing the answer related to the question, or getting the selectOptions
if the display type is a picklist. Wrapper classes are used very heavily in the real-life version of the simplified markup below.
<!-- If the question has been defined as a radio button -->
<apex:outputPanel layout="none" id="radioPanel" rendered="{!Question.DisplayType__c == 'Radio'}">
<apex:selectRadio id="selectRadioInput" value="{!Answer.AnswerValue__c}">
<apex:selectOptions value="{!SelectOptions}" />
</apex:selectRadio>
</apex:outputPanel>
<!-- If the question has been defined as text input -->
<apex:outputPanel layout="none" id="textPanel" rendered="{!(Question.DisplayType__c == 'Text')}">
<apex:inputText id="textInput" value="{!Answer.AnswerValue__c}" />
</apex:outputPanel>
<!-- If the question has been defined as textArea input -->
<apex:outputPanel layout="none" id="textPanel" rendered="{!(Question.DisplayType__c == 'Text Area')}">
<apex:inputTextArea id="textAreaInput" rows="3" value="{!Answer.AnswerValue__c}" />
</apex:outputPanel>
<!-- If the question has been defined as a checkbox input -->
<apex:outputPanel layout="none" id="checkboxPanel" rendered="{!Question.DisplayType__c == 'Checkbox'}">
<apex:inputCheckbox id="checkboxInput" value="{!Answer.AnswerValue__c}" />
</apex:outputPanel>
<!-- If the question has been defined as a single picklist -->
<apex:outputPanel layout="none" id="picklistPanel" rendered="{!(Question.DisplayType__c == 'Picklist')}" >
<apex:selectList id="selectListInput" value="{!Answer.AnswerValue__c}" multiselect="false" size="1" >
<apex:selectOptions value="{!SelectOptions}" />
</apex:selectList>
</apex:outputPanel>
<!-- If the question has been defined as a multiselect picklist -->
<apex:outputPanel layout="none" id="multiPicklistPanel" rendered="{!(Question.DisplayType__c == 'Picklist (Multi-Select)')}" >
<apex:selectList id="multiPicklist" value="{!Answer.AnswerValue__c}" multiselect="true" size="5">
<apex:selectOptions value="{!SelectOptions}" />
</apex:selectList>
</apex:outputPanel>
value=".."
attribute possible; three fields with rendered= will do the trick – cropredy Mar 25 '16 at 22:02