+ Start a Discussion
Anurag Sharma 244Anurag Sharma 244 

How do i enable the edit mode on the base of checkbox is checked or not....i am new in salesforce. so anyone please help me to code.

How do i enable the edit mode on the base of checkbox is checked or not....i am new in salesforce. so anyone please help me to code.
i want a list with Ist column of checkbox and then rest are contact fields like name etc... and then if i checked the checkbox i want enable the edit mode using the action function.
please sort it out...
Best Answer chosen by Anurag Sharma 244
Gooch ForeverGooch Forever
Hi Anurag

Here is the code for both Controller and Page. Then do necessity change after wards.

public class checkBoxEdit{

    public List<Contact> contList {get;set;}
    public List<wrapperClass> wrapList{get;set;}

    public wrapperClass wrap{get;set;}   
     
    public checkBoxEdit(){
        wrapList = new List<wrapperClass>();
        contList = new List<contact>();
        contList = [Select Id,Name,Email,LastName From Contact];
        for(contact c : contList){
             wrapList.add(new wrapperClass(c));      
        }     
    }
   
    public class wrapperClass{
   
        public Boolean isEdit{get;set;}
        public Contact cont {get;set;}
        
        public wrapperClass(Contact con){
            this.cont = con;         
        }
    }   
}



<apex:page controller="checkBoxEdit" >
    <apex:form >
        <apex:pageblock id="pb">
            <apex:pageblockTable value="{!wrapList}" var="w" >
                <apex:column >              
                    <apex:inputCheckbox value="{!w.isEdit}">
                        <apex:actionSupport event="onchange" reRender="pb"/>    
                     </apex:inputCheckbox>              
                </apex:column>
                <apex:column >
                    <apex:outputText value="{!w.cont.email}" rendered="{!w.isEdit == False}"></apex:outputText>
                    <apex:inputText value="{!w.cont.email}" rendered="{!w.isEdit == True}"/>               
                </apex:column>    
            </apex:pageblockTable>      
        </apex:pageblock>
    </apex:form>   
</apex:page>

All Answers

sweetzsweetz
You can use rerender function to achieve that. Here is the link that meets your requirement. 
http://stackoverflow.com/questions/8578748/display-a-text-field-after-a-checkbox-is-checked-in-visualforce 
asish1989asish1989
Hi Anurag

Here is page for your requirment

<apex:page >
<apex:form >
    <script>
         function confirmDisbaled(ifchecked, id1 ,id2,id3) {
       
               
                 document.getElementById(id1).disabled = ifchecked;
                 document.getElementById(id2).disabled = ifchecked;
                 document.getElementById(id3).disabled = ifchecked;                                
          
         
           }
    </script>
    <apex:pageBlock id="theblock">
  <apex:actionRegion >
        <apex:outputPanel id="panel1">
        <apex:pageBlockSection title="PST" id="PST">
           <apex:inputCheckbox label="Global" id="gbl" onchange="return confirmDisbaled(this.checked, '{!$Component.lcl}','{!$Component.cntry}');"/>
           
           <apex:inputCheckbox label="Local" id="lcl" onchange="return confirmDisbaled(this.checked, '{!$Component.gbl}','{!$Component.cntry}');"/>
           

            <apex:inputCheckbox label="Country" id="cntry" onchange="return confirmDisbaled(this.checked, '{!$Component.lcl}','{!$Component.gbl}');"/>
            

         </apex:pageBlockSection>
         </apex:outputPanel>        
</apex:actionRegion>
</apex:pageBlock>
</apex:form>
</apex:page>

Important :

If this is what you where looking for then please mark it as a solution for others benefits.

Thank You
Anurag Sharma 244Anurag Sharma 244
hi ashish1989.
i want to enable input field on the check of check box.
if check box is CHECKED then input field change to edit mode, and i can make entry.
Gooch ForeverGooch Forever
Hi Anurag

Here is the code for both Controller and Page. Then do necessity change after wards.

public class checkBoxEdit{

    public List<Contact> contList {get;set;}
    public List<wrapperClass> wrapList{get;set;}

    public wrapperClass wrap{get;set;}   
     
    public checkBoxEdit(){
        wrapList = new List<wrapperClass>();
        contList = new List<contact>();
        contList = [Select Id,Name,Email,LastName From Contact];
        for(contact c : contList){
             wrapList.add(new wrapperClass(c));      
        }     
    }
   
    public class wrapperClass{
   
        public Boolean isEdit{get;set;}
        public Contact cont {get;set;}
        
        public wrapperClass(Contact con){
            this.cont = con;         
        }
    }   
}



<apex:page controller="checkBoxEdit" >
    <apex:form >
        <apex:pageblock id="pb">
            <apex:pageblockTable value="{!wrapList}" var="w" >
                <apex:column >              
                    <apex:inputCheckbox value="{!w.isEdit}">
                        <apex:actionSupport event="onchange" reRender="pb"/>    
                     </apex:inputCheckbox>              
                </apex:column>
                <apex:column >
                    <apex:outputText value="{!w.cont.email}" rendered="{!w.isEdit == False}"></apex:outputText>
                    <apex:inputText value="{!w.cont.email}" rendered="{!w.isEdit == True}"/>               
                </apex:column>    
            </apex:pageblockTable>      
        </apex:pageblock>
    </apex:form>   
</apex:page>
This was selected as the best answer
Anurag Sharma 244Anurag Sharma 244
Thanks for your support Gooch Forever.