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
ArunaAruna 

Disable the check box which is in component when I click the save button on vf page

Hi All,

 

I have one component(testcomponent) which is having a check box like sample below

 

<apex:component controller="test" id="check">

<apex:inputCheckbox value={}" id="bopt" />

</apex:component>

 

And one Vf Page which has the component in it  and also one save button like

<apex:page controller="test1" id="pid">

<apex:commandButton value=" Save" title="Save Entire Page" />

<c:testcomponent>

</apex:page>

 

 I need to disable the check box if it already been checked when page is loaded.

this i have done using the java script function

below function is working fine , it disabling the check box when the  page is loading.

 

function disableCheckBox(){    

 if({!accountDetail.OptOutSettings.brandOptOut==true}  ){
    document.getElementById('{!$Component.check.bopt}').disabled=true;
    }
    else{
    document.getElementById('{!$Component.check.bopt}').disabled=false;
    }
}

 Function was called in document ready state 

$(document).ready(function() {

disableCheckBox();

}

 

but when i click save button on VF page checkbox is enabling again and also lost the previous data.

Can anyone suggest how to disable the check box which is  in component when I click the save button on vf page.

 

Thank you

 

Damien_Damien_

Off the top of my head.... create a custom controller for that component that has a value of

boolean isDisabled;

 

Set this value inside of the constructor and when the save button gets clicked

 

<apex:inputCheckbox value={}" id="bopt" disabled="{!isDisabled}" />

 

When the checkbox is clicked, also set 'isDisabled = true;' in your controller.

 

This is the first solution that came to mind, I'm sure there might be cleaner ways.

ArunaAruna

Hi Damine,

 

How to check whether check box is selected or in controller.

 

Mean your saying set 'isDisabled = true when check box is clicked. how to check wheter check box is selectd or not in controller.

 

Thank you

Damien_Damien_

Build a wrapper class to put this into.  Somethign similar to:

 

public class OuterClass

{

  public List<InnerWrapper> someList;{get;private set;}

  ...//standard stuff

 

  public class InnerWrapper

  {

    public sObject someObj{get;set;}

    public boolean isDisabled{get;set;}

    public InnerWrapper(SObject someObj)

    {

      this.someObj = someObj;

    }

  }

}

ArunaAruna

Hi Damine,

 

Thank you so much for the replay.

 

I solved my problem to day just ihave metion as you send like on check box

<ape:inputcheckbox disable={!IF(my business condition,true,false)}/>

 

Thank you

Damien_Damien_

O Ok, that works.  You could simplify that line to:

 

<apex:inputcheckbox disable="{!my business condition}" />

Adil_SFDCAdil_SFDC

Hi Damie

 

I think you can help me here.  I want to disable a check box. My vf page gets document list from a website And it has checkboxes. I want to disable the check box if  in my documentlist "Internal Only' value is True.

Here is my VF Page 

    
            <apex:pageBlockTable value="{!documentList}" var="doc" id="docTableId" first="{!firstRecPosition}" rows="{!rowLimit}" rendered="{!NOT(ISNULL(documentList))}">
                <apex:column >
                
                    <apex:inputCheckbox value="{!doc.isChecked}"/>
                </apex:column>
                <apex:column >
                   <apex:facet name="header">
                        <apex:commandLink value="Title" action="{!doSort}" rerender="docTableId"  status="statusId">
                            <apex:param name="sortField" value="Title" assignTo="{!sortField}"/>
                        </apex:commandLink>
                        
                    </apex:facet>
                     <apex:outputLink target="{!doc.url}" value="{!doc.url}">{!doc.title}</apex:outputLink>
                </apex:column>
                 <apex:column >
                    <apex:facet name="header">
                  
                         <apex:commandLink value="Internal Only "  action="{!doSort}" rerender="docTableId"  status="statusId">
                            <apex:param name="sortField" value="internalOnly " assignTo="{!sortField}"/>
                        </apex:commandLink>

 

public void createDocuments(JSONParser parser)
    {
        documentList = new List<Document>();
        Document doc = new Document();
        Integer position = 0;
        while (parser.nextToken() != null) 
        {
         if (parser.getCurrentToken() == JSONToken.START_OBJECT) 
            {   
                if(doc.title != null)// && doc.url != null && doc.rating != null && doc.filetype != null && doc.id != null && doc.description != null)
                {
                    doc.position = position;
                    position++;
                    documentList.add(doc);
                    
                    doc = new Document();
                } 
                    
            }
            if (parser.getCurrentToken() == JSONToken.FIELD_NAME) 
            {
                if(parser.getText() == 'title')
                {
                    parser.nextToken();
                    doc.title = parser.getText();
                }
                if(parser.getText() == 'id')
                {
                    parser.nextToken();
                    doc.id = parser.getText();
                }
                if(parser.getText() == 'description')
                {
                    parser.nextToken();
                    doc.description = parser.getText();
                }
                if(parser.getText() == 'url')
                {
                    parser.nextToken();
                    doc.url = parser.getText();
//                    system.debug('URL is  '+doc.URL);
                }
                if(parser.getText() == 'filetype')
                {
                    parser.nextToken();
                    doc.fileType = parser.getText();
                }
                if(parser.getText() == 'rating')
                {
                    parser.nextToken();
                    doc.rating = parser.getText(); 
                }
                if(parser.getText() == 'internalonly')
                {
                    parser.nextToken();
                    doc.internalOnly = Boolean.valueOf(parser.getText());
                   if(doc.internalOnly == true){
                   doc.internonly ='Yes';
                   }else
                   doc.internonly='No';
                    
                }
               /*  if(parser.getText() == 'Status')
                {
                    parser.nextToken();
                    doc.Status = parser.getText();
                }
                if(doc.title != null)// && doc.url != null && doc.rating != null && doc.filetype != null && doc.id != null && doc.description != null)
                {
                    doc.position = position;
                    position++;
                    documentList.add(doc);
                    
                    doc = new Document();
                }*/
                    
            }
        }

 Please help

Damien_2Damien_2

Currently... I'm locked out of my name.

<apex:inputCheckbox value="{!doc.isChecked}" disabled="{!doc.insernalOnly}" />
Adil_SFDCAdil_SFDC

Made my day Big time