Skip to main content

Disabling Checkbox Inside PageBlockTable

Hi All
I had come across in a requirement,the Requirement  was to select one record and disable all the records after selecting in that table. I have done it by using JavaScript, I think it will help you.
This is the page.
<apex:page>
     <apex:form>
            <script>
                   function checkboxuse(tag) {
                        var menus  = document.getElementsByClassName("Teststyle");
                        if (tag.checked == true) {
                             for (var i = menus.length - 1; i >= 0; i--)
                             {
                                    menus[i].disabled = true;
                             }
                            tag.disabled = false;
                        }
                       else {
                             for (var i = menus.length - 1; i >= 0; i--)
                             {
                                     menus[i].disabled = false;
                             }
                         }
                     }     
              </script>
             <apex:PageBlock>
                      <apex:pageBlockTable value = "{!listofRecords}" var = "c" >
                                <apex:column header = "Select" >
                                        <apex:inputCheckBox value = "{!c.selected}" id="tst" styleClass="Teststyle"                             onchange="return checkboxuse(this)"/>
                                </apex:column>
                               <apex:column header = "FieldName"> 
                                         <apex:inputFiled value = "{!c.filedAPIName}" /> 
                              </apex:column>
                     </apex:pageBlockTable>  
             </apex:PageBlock>
         </apex:form>
  </apex:page>

You have to use wrapper class, listofRecords should be a wrapper class List.




Comments

Anonymous said…
Hi,
Good post. I have a requirement where i have to check a checkbox based on condition.
E.g I have 3 objects contact,application and verifier. Verifier is junction object b/w contact and application. In vf page i have a pagebocktable with 2 columns. 1st column has all contacts and 2 column is for verifier and has checkboxes. If a contact is verifier then checkbox should be checked.
Generally we can display list of records of one Object in a pageblock table.For example suppose there are two objects Account and Contact. We can not display list of Accounts records as well as list of Contacts record in one pageblock table.


listofRecords should list of records of one object.
Anonymous said…
Hi please check this for the above asked question. http://salesforce.stackexchange.com/questions/16511/rendering-checkbox-based-on-value
I saw that link,but there only contact name is displayed in one page block table.other one is check box. It is easy we can display.
Unknown said…
Hi Ashish,

I have requirement related to the checkbox is disabled whenever input field value is zero
I have one wrapper list, in this wrapper having one checkbox and one input field

I am trying two way but not working properly





Apex code
//============================================
public boolean checkBoxDisabled {get;set;}
Public void quantityZero(){
for(Integer i = 0; i < wrapList.size();i++){
if(Decimal.valueOf(wrapList[i].azure.Quantity__c) <= 0){
checkBoxDisabled = true;
}
}
}
//===============================================

Popular posts from this blog

How to Create a Tooltip in Lightning Datatable ?

Imagine you have a datatable displaying a list of Contact records , and one of the columns shows the Account Name . The Account Name is a hyperlink that allows users to navigate to the Account record page. But what if users want to take a quick glance at some key Account fields —like Phone or Address—without navigating to the Account record? In Salesforce Classic, this was achieved using the Mini Page Layout feature from standard page. However, in Lightning Experience, we can implement a similar feature by adding a tooltip to the data table. Solution Overview: We’ll create a Lightning Web Component (LWC) that: Displays a data table with a clickable Account Name . Provides a tooltip that shows the Account's Phone and Address fields when users hover over the Account Name. Implementation Steps: 1. Data Preparation We need to retrieve the following fields for each Contact and its associated Account: Contact Fields : Name, Phone, Email Account Fields : Name, Phone, Billing Addre...

📆 How to Get the Start and End Date of the Previous Quarter in Apex ?

 When working with Salesforce data, it's often necessary to filter or report on records from a specific quarter . If you're looking to retrieve the start and end dates of the previous quarter based on the current date, here’s a simple and reusable Apex utility you can use. 🔧 Apex Utility Methods Below are two helper methods: getStartDate() — Calculates the start date of the previous quarter . getEndDate() — Calculates the end date of the previous quarter , based on the start date. // Helper method to get the start date of the previous quarter private Date getStartDate () {     Date today = Date . today ();     Integer currentYear = today . year ();     Integer currentMonth = today . month ();     // Determine the first month of the previous quarter     Integer previousQuarterStartMonth = (( currentMonth - 1 ) / 3 ) * 3 + 1 - 3 ;     // Adjust the year if the previous quarter falls in the previ...

How to Create/Delete file attachments(Content Document) through Apex ?

 There are 3 standard salesforce objects to store file attachments. Content Document, ContentDocumentVersion, ContentDocumentLink.  Here is the article to talk about these objects and relationship.  https://www.forcetalks.com/blog/contentdocument-and-contentversion-in-salesforce-an-overview/ ContentDocumentVersion ContentDocumentLink This post is all about how to create/delete content document though Apex. Here is code snippet // Insert Content Version record ContentVersion contentVersionRec = new ContentVersion(Title='filename',PathOnClient ='FileName.pdf',VersionData = bodyBlob,origin = 'H'); INSERT contentVersionRec; // this will insert one record in ContentDocument and ContentVersion , ContentDocument  is parent and  ContentVersion is child record // get contentdocument id contentVersionRec = [SELECT Id, Title, ContentDocumentId FROM ContentVersion WHERE Id = :contentVersionRec .Id LIMIT 1]; // Create Content Document Link record- This will attach ...