You need to sign in to do that
Don't have an account?
Sreeram Chakrapani
InputText Field Disabling on a VF Page entry
Hi,
I am looking to disable couple of fields when I launch my Visual Force Page from a Custom Button, can I get som help in terms of a sample code ? I know this is basic but am new to Apex and Visual Force. Appreciate the help
Thanks
SC
I am looking to disable couple of fields when I launch my Visual Force Page from a Custom Button, can I get som help in terms of a sample code ? I know this is basic but am new to Apex and Visual Force. Appreciate the help
Thanks
SC
go through the example below.
apex class:
public class disableInputField1 {
public Opportunity opp {get; set;}
public Boolean disableInput {get; set;}
public disableInputField1 (){
opp = new Opportunity();
}
public void disableCloseDateInput(){
disableInput = true;
}
public void enableCloseDateInput(){
disableInput = false;
}
}
visualforce page:
<apex:page controller="disableInputField1">
<apex:form >
<apex:commandButton value="Disable inputField" action="{!disableCloseDateInput}" rerender="oppName"/>
<apex:commandButton value="Enable inputField" action="{!enableCloseDateInput}" rerender="oppName"/><br/><br/>
Opportunity Name:%
<apex:outputPanel id="oppName">
<apex:inputField value="{!opp.CloseDate}" id="oppNameInput" required="false"/>
<script>document.getElementById('{!$Component.oppNameInput}').disabled = {!disableInput}; </script>
</apex:outputPanel>
</apex:form>
</apex:page>
Note :we can also disable input fields by using styles.
for example document.getElementById('elementid').style.display='none';
if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
All Answers
I want to show them in the Visual Force page but just like a ready only text field which is greyed out. Thanks in advance
SC
go through the example below.
apex class:
public class disableInputField1 {
public Opportunity opp {get; set;}
public Boolean disableInput {get; set;}
public disableInputField1 (){
opp = new Opportunity();
}
public void disableCloseDateInput(){
disableInput = true;
}
public void enableCloseDateInput(){
disableInput = false;
}
}
visualforce page:
<apex:page controller="disableInputField1">
<apex:form >
<apex:commandButton value="Disable inputField" action="{!disableCloseDateInput}" rerender="oppName"/>
<apex:commandButton value="Enable inputField" action="{!enableCloseDateInput}" rerender="oppName"/><br/><br/>
Opportunity Name:%
<apex:outputPanel id="oppName">
<apex:inputField value="{!opp.CloseDate}" id="oppNameInput" required="false"/>
<script>document.getElementById('{!$Component.oppNameInput}').disabled = {!disableInput}; </script>
</apex:outputPanel>
</apex:form>
</apex:page>
Note :we can also disable input fields by using styles.
for example document.getElementById('elementid').style.display='none';
if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
http://www.w3schools.com/jsref/prop_html_disabled.asp