You need to sign in to do that
Don't have an account?
aveforstudy1.3196212890020557E
How to disable a input Text and then enable it based on selected value of check box
Hi,
I am in need of an urgent help. I want to disable a input text based on the selcted value from a drop down.
I am able to achieve it by using actionSupport on the change event of the dropdown, but it does not work when i want to make the disabled field back to enabled. Surprisingly the actionSupport's action does not get called.
Any help would be appreciated.
Below is the working solution for this
<apex:page id="thepage" standardController="Account" >
<apex:form >
<apex:inputField value="{!Account.check__c}">
<apex:actionSupport event="onchange" rerender="pan" status="counterStatus" />
</apex:inputField>
<apex:outputPanel id="pan">
<apex:inputText id="test" disabled="{!IF(Account.check__c==true,true,false)}" />
</apex:outputPanel>
<apex:actionStatus id="counterStatus" startText=" (incrementing...)" stopText=" (done)"/>
</apex:form>
</apex:page>
Hi please mark it as solved if it works for you
All Answers
Try this
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Hey,
Thanks for the quick response.
Actually i want to make use of <apex:actionSupport> as i want to disable the input text once the dropdown's value changes.
Here's the code snippet.
<apex:selectList size="1" value="{!selecteddate}">
<apex:selectOptions value="{!year}"></apex:selectOptions>
<apex:actionSupport event="onchange" action="{!disablefield}" reRender="jan"/>
</apex:selectList>
/*Inside the page block table i heva the following column*/
<apex:column headerValue="Jan" >
<apex:inputText value="{!MB.Jan}" disabled="{!disableJan}" id="jan" />
</apex:column>
The problem is that disablefield is not called at all if the previously jan was disabled.
Can you post your apex method ?
Below is the code you need its is for a checkbox you can just change the field
1.)Select box to checkbox
2.)checkbox to inputText
public with sharing class testComponent {
public testComponent() {
}
public Account acc{get;set;}
public testComponent(ApexPages.StandardController controller) {
//acc=(account)controller.getrecord();
// string accid=(account)controller.getrecord().id;
acc=[select id,AccountSource,check__c from account where id='0019000000CJ6QZ'];
}
public pagereference changeCheckBox(){
acc.check__c=true;
return null;
}
}
public void disablefield(){
//monthsToDisable;
isDisabled = false;
monthsToDisable = new List<String>();
System.debug('inside disablefield '+monthsToDisable);
List<Integer> tempMonth = new List<Integer>();
Date todaysDate = System.today();
DateTime tempDate = System.now();
Integer Month = todaysDate.month();
String Year = tempDate.format('yyyy');
System.debug('selecteddate is '+selecteddate+'current Year is '+Year);
if(selecteddate==Year){
if(Month!=1){
for(integer i=Month-1;i>0;i--){
tempMonth.add(i);
}
}
for(Integer m:tempMonth){
if(m==1){
monthsToDisable.add('Jan');
}
if(m==2){
monthsToDisable.add('Feb');
}
if(m==3){
monthsToDisable.add('Mar');
}
if(m==4){
monthsToDisable.add('Apr');
}
if(m==5){
monthsToDisable.add('May');
}
if(m==6){
monthsToDisable.add('Jun');
}
if(m==7){
monthsToDisable.add('Jul');
}
if(m==8){
monthsToDisable.add('Aug');
}
if(m==9){
monthsToDisable.add('Sept');
}
if(m==10){
monthsToDisable.add('Oct');
}
if(m==11){
monthsToDisable.add('Nov');
}
if(m==12){
monthsToDisable.add('Dec');
}
}
}
System.debug('monthsToDisable '+monthsToDisable);
}
This function prepares a list, having the month names that needs to be disabled.
Following is the function that will return true or false to the disabled attribute of input text.
public boolean getdisableJan(){
System.debug('monthsToDisable @@@@@'+monthsToDisable);
boolean isDisabled;
for(String s:monthsToDisable){
if(s=='Jan'){
isDisabled= true;
return isDisabled;
}
}
return isDisabled;
}
please ignore
isDisabled = false; in disablefield() function
You dont have to use the FLAG in controller you can just use the checkbox as a flag and rerender the inputtext panel as given in my example
rendered="{!IF(acc.check__c==true,true,false)}"
here acc.check__c is a checkbox which when checked says true otherwise false
Hey,
If the field is enabled then its gets disabled as per the logic, but if the filed is disabled then in that case it does not go back to being enabled.
Am i missing anything, or is there any other approach i can take. I have already tried using javascript but its of no use.
thanks Abhay, but i am not making use of any fields here, its just a input text.
Below is the working solution for this
<apex:page id="thepage" standardController="Account" >
<apex:form >
<apex:inputField value="{!Account.check__c}">
<apex:actionSupport event="onchange" rerender="pan" status="counterStatus" />
</apex:inputField>
<apex:outputPanel id="pan">
<apex:inputText id="test" disabled="{!IF(Account.check__c==true,true,false)}" />
</apex:outputPanel>
<apex:actionStatus id="counterStatus" startText=" (incrementing...)" stopText=" (done)"/>
</apex:form>
</apex:page>
Hi please mark it as solved if it works for you
Hi Please mark this as solved if your issues have been resolved
Hi,
You can use a javascript in the page... if u r comfortable with it...
It would be very easy to implement....
Thanks,
Prasanth
Hi Abhay
its working good but its taking more than 30 sec of time can't we make it quick.