I have a custom object with 5 Questions and field Api Names are Q1__c, Q2__c, Q3__c, Q4__c, Q5__c
Requirement :
This is a Question answer from with question having more than 40 characters so i am doing in the visualforce page
Page:
<apex:page standardcontroller="Phone_Screen__c" extensions="PhoneScreenController">
<apex:form>
<apex:actionFunction name="sendvalues" action="{!process}" reRender="renderme">
<apex:param assignTo="{!option}" name="value1" value="" />
</apex:actionFunction>
<apex:pageBlock>
<apex:pageBlockSection>
<apex:inputField value="{!Phone_Screen__c.Type__c}" styleClass="type" onchange="callmethod()" />
<!--This is a custom picklist field-->
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock id="renderme">
<apex:pageBlockSection rendered="{!panel1}">
<apex:variable var="count" value="{!0}"/>
<apex:repeat value="{!questions}" var="i">
<span id="question{!count}">{!questions[count].Question__c}</span>
<textarea id="answer{!count}"></textarea>
<apex:variable var="count" value="{!count + 1}"/>
</apex:repeat>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<script type="text/javascript">
function callmethod(){
sendvalues(document.getElementsByClassName('type')[0].value);
}
</script>
</apex:page>
Controller:
public class PhoneScreenController {
public Boolean panel1{get; set;}
public String option{get;set;}
public PhoneScreenController(ApexPages.StandardController controller) {
panel1 = false;
}
public pageReference process(){
if(option == 'Value1') {
panel1 = true;
}
return null;
}
public List<Questions__c> getquestions(){
List<Questions__c> mc = Questions__c.getAll().values();
return mc;
}
}
Issue: I am trying to get the answer for a particular question in textarea and I am looking to save this value to the corresponding question while creating the record. How can I map this value to that question while creating the record as questions come from custom settings and the number of questions can keep changing.
Right now I created a custom setting which has the following fields: - apiname__c : to store the field apiname - question__c: for the question