You need to sign in to do that
Don't have an account?
Problem disabling and enabling an inputField
I have a visualforce page that is used to get customer information. I want the form to disable an inputField that asks for the customers age if the customer checks the Do Not Disclose box. I have been unable to get this to work unless I use an inputText box and set it to a string variable.
Controller Code:
VisualForce Page:
<apex:pageBlock id="agedisable" mode="edit"> <apex:actionRegion > <apex:inputText value="{!age}" disabled="{!disable}"/> <apex:inputCheckbox value="{!disclose}"> <apex:actionSupport event="onchange" action="{!doDisable}" reRender="agedisable"/> </apex:inputCheckbox> </apex:actionRegion> </apex:pageBlock>
I want to be able to use an inputField instead of an inputText field but when I try to disable an inputField or an inputText field set to an integer variable it will disable when I check the inputCheckbox but when I uncheck it, it remains disabled.
Also, when I have the age field set to string and it is able to disable and enable properly, once I check the checkbox the formatting of my page changes and a large space shows up between the checkbox field and the next field in my form. Is there a way to avoid this?
- Jim Hutcherson
I have another idea.dont know works for you or not.
Use output panel to show inputText field and inputField when you check the check box.
something like this....
<apex:actionRegion >
<apex:outputPanel id="p1" rendered="{!panel1}">
<apex:inputText value="{!Name}" disabled="{!disable}"/>
</apex:outputPanel>
<apex:outputPanel rendered="{!panel2}">
<apex:inputField value="{!Name}"/>
</apex:outputPanel>
<apex:inputCheckbox value="{!disclose}">
<apex:actionSupport event="onchange" action="{!doDisable}" reRender="agedisable"/>
</apex:inputCheckbox>
</apex:actionRegion>
cheers
suresh
Find below a sample code :
VF CODE:
<apex:page controller="disableInputField">
<apex:form >
<apex:actionFunction action="{!disableCloseDateInput}" rerender="oppName"/>
<apex:actionFunction action="{!enableCloseDateInput}" rerender="oppName"/>
<apex:inputCheckbox/> <b>Disable inputField</b><br/>
<apex:inputCheckbox onclick="actinFunc2()"/> <b>Enable inputField</b><br/><br/>
Opportunity Name:
<apex:outputPanel>
<apex:inputField value="{!opp.CloseDate}" required="false"/>
<script>document.getElementById('{!$Component.oppNameInput}').disabled = {!disableInput}; </script>
</apex:outputPanel>
</apex:form>
</apex:page>
Controller code:
public class disableInputField {
public Opportunity opp {get; set;}
public Boolean disableInput {get; set;}
public disableInputField(){
opp = new Opportunity();
}
public void disableCloseDateInput(){
disableInput = true;
}
public void enableCloseDateInput(){
disableInput = false;
}
}