function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Amita TatarAmita Tatar 

pass selected checkbox field labels to a text area field

Hi all,

I have a VF page where i have displayed sObject labels dynamically on this VF page. These field labels are associated with checkboxes.
I want that whichever checkboxes are selected , there labels should get stored in a text area field at the backend.
I will paste my code below. Please help me for the same.
APEX CLASS::::

public class getLabel{

public List<WrapperClass> listWrapper {get;set;}
public Map<String,String> labelMap;
public String resultString {get;set;}  

public getLabel(ApexPages.StandardController controller) {
    listWrapper = new List<WrapperClass>();
    labelMap = new Map<String,String>();
    labelMap = retLabelMap('ProposalFields__c');
    for(String s : labelMap.values()){
        listWrapper.add(new WrapperClass(s,false));
    }
}

public class WrapperClass {  
    public Boolean checkBool {get;set;}
    public String fieldNme{get;set;}  
    public WrapperClass(String prop,Boolean checkBool ){  
        this.fieldNme = prop;  
        this.checkBool = checkBool ;  
    }  
}

public Static Map<String,String> retLabelMap(String type){
    Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe();
    Schema.SObjectType s= m.get(type);
    Map<String, Schema.SObjectField> fieldMap = s.getDescribe().fields.getMap();
    Map<String,String> aMap = new Map<String,String>();
    for (String fieldName: fieldMap.keySet()) {
        aMap.put(fieldName,fieldMap.get(fieldName).getDescribe().getLabel());
    }

    return aMap;
}

public void saveCheckboxValue(){
     Proposal_Form__c p = new Proposal_Form__c();
     p.Fields_Associated__c = resultString;
     insert p;
 }
 
public PageReference getSelected(){
   return null;
}



}



VF PAGE:


<apex:page showHeader="false" sidebar="false" standardController="Proposal_Form__c" extensions="getLabel">
<apex:form >
<style>
.panelWrapper .mainTitle {
   text-align :center;
    
}
</style>
<apex:outputPanel styleClass="panelWrapper" layout="block">
<apex:pageBlock title="Proposal Form">
<apex:pageBlockSection title="Service Requirements">
<apex:inputField value="{!Proposal_Form__c.Service_Family__c}"/>
<apex:inputfield value="{!Proposal_Form__c.Service_Type__c}"/>
<apex:inputField value="{!Proposal_Form__c.Sub_Service_Category__c}"/>
</apex:pageBlockSection>

<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="Save" action="{!Save}"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="Available fields">
<apex:repeat var="lab" value="{!listWrapper}">
    <apex:pageblockSectionItem >
        <apex:outputlabel value="{!lab.fieldNme}"/>
        <apex:inputCheckbox value="{!lab.checkBool}"/>
    </apex:pageblockSectionItem> 
</apex:repeat>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>

</apex:form> 
</apex:page>
Thanks,
Amita Tatar
 
_Prasu__Prasu_
You can write a Javascript method which will get executed onchange event and pass a parameter of fieldname.
Muzammil BajariaMuzammil Bajaria
public getLabel(ApexPages.StandardController controller) {
       listWrapper = new List<WrapperClass>();
       labelMap = new Map<String,String>();  
       labelMap = retLabelMap('ProposalFields__c');  
       for(String s : labelMap.values()){
              listWrapper.add(new WrapperClass(s,false));
         }
        listWrapper.sort();
}

Trysorting the list which you are displaying
Amita TatarAmita Tatar
Can you explain me in detail?