+ Start a Discussion
Rohit PaulRohit Paul 

Enable/Disable inputText using checkbox - ActionFuntion

Hi,

 

Need to have a page where the inputText field must be activated only when the checkbox next to it is tagged.

Can you please provide me an example?

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
Abhay AroraAbhay Arora

You can use below code for reference i am changing checkbox on this you can reverse the fields

 

 

<apex:page id="thepage" standardController="Account" extensions="testComponent">
<apex:form >
    <apex:inputField value="{!acc.AccountSource}">
        <apex:actionSupport event="onchange" action="{!changeCheckBox}" rerender="pan" status="counterStatus" />
    </apex:inputField>
            <apex:outputPanel id="pan">
            <apex:inputField id="test" value="{!acc.check__c}"/>
        </apex:outputPanel>
        <apex:actionStatus id="counterStatus" startText=" (incrementing...)" stopText=" (done)"/>
</apex:form>
</apex:page>

 

public with sharing class testComponent {

    public testComponent() {

    }

    public Account acc{get;set;}
    public testComponent(ApexPages.StandardController controller) {
        acc=[select id,AccountSource,check__c from account where id='0019000000CJ6QZ'];
    }
    public pagereference changeCheckBox(){
        acc.check__c=true;
        return null;
    }

}

 

All Answers

NIKHIL_SFDCNIKHIL_SFDC

Hi Rohit, 

 

Yes this is possible but this is not a standard functionality. You have to create a visualforce page for this then you can achieve this.

 

Rohit PaulRohit Paul

Ya I already achieved to do so ....

 

Used actionSupport for the checkbox on the event ónChange which worked.

Rerendering the required region assisted in locking or unlocking the field but the response time is slow for field opening or closing.

 

Is there any method which could improve the respose time of the change?

SeAlVaSeAlVa

Try the following code and if it fits you, adapt it ;)

 

<apex:page standardController="Lead">
  <apex:form >
  <apex:pageBlock >
    <apex:pageBlockSection >
      <apex:inputField id="fieldToChange" value="{!lead.title}"/>
      <apex:inputCheckbox onchange="document.getElementById('{!$Component.fieldToChange}').disabled=this.checked;"/>
    </apex:pageBlockSection>
  </apex:pageBlock>
  </apex:form>
</apex:page>

 

Abhay AroraAbhay Arora

You can use below code for reference i am changing checkbox on this you can reverse the fields

 

 

<apex:page id="thepage" standardController="Account" extensions="testComponent">
<apex:form >
    <apex:inputField value="{!acc.AccountSource}">
        <apex:actionSupport event="onchange" action="{!changeCheckBox}" rerender="pan" status="counterStatus" />
    </apex:inputField>
            <apex:outputPanel id="pan">
            <apex:inputField id="test" value="{!acc.check__c}"/>
        </apex:outputPanel>
        <apex:actionStatus id="counterStatus" startText=" (incrementing...)" stopText=" (done)"/>
</apex:form>
</apex:page>

 

public with sharing class testComponent {

    public testComponent() {

    }

    public Account acc{get;set;}
    public testComponent(ApexPages.StandardController controller) {
        acc=[select id,AccountSource,check__c from account where id='0019000000CJ6QZ'];
    }
    public pagereference changeCheckBox(){
        acc.check__c=true;
        return null;
    }

}

 

This was selected as the best answer
Rohit PaulRohit Paul

Hi Abhay,

 

Thanks for the example, I had already used this kind of logic for my case.

The only isse I face is the delay in field opening and closing based on checkbox.

As you understand, using JavaScript the process is much faster in basic HTML, but in Visualforce there is a delay in the responce.

 

Other than that the code is working just fine :)