You need to sign in to do that
Don't have an account?
Venkat Maddipati
How to disable the apex:inputField component value based on rendering criteria?
Hi ,
How to disable the apex:inputField component value based on rendering criteria?
Thanks in advance.
Sample Code:
Visualforce page:
<apex:page controller="sample">
<script type="text/javascript">
</script>
<apex:form >
<apex:pageMessages />
<apex:pageBlock >
<apex:pageBlockSection columns="2">
<apex:pageblockSectionItem >
<apex:outputLabel value="Metro"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:inputCheckbox value="{!metro}">
<apex:actionSupport event="onchange" reRender="a" action="{!demo}"/>
</apex:inputCheckbox>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:outputLabel value="City"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:inputField value="{!city}" id="a" disabled="{!bool}"/>
</apex:pageblockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Code:
public class sample
{
public Boolean metro {get;set;}
public Boolean city {get;set;}
public Boolean bool {get;set;}
public sample()
{
}
public void demo()
{
if(metro)
{
bool = true;
}
else
{
bool = false;
}
}
}
Regards,
Magulan D
Salesforce.com certified Force.com Developer.
SFDC Blog
If this post is your solution, kindly mark this as the solution.
Thanks for ur reply..
The apex:inputField component is not supporting the attribute as "disabled".
You can do this via jQuery. Import the jQuery library as a static resource first -- in my example I named the resource JQuery_1_7_2. Then you can do this within your page:
You define the property shouldDisable on your controller and can initialize it in your constructor or later in the code:
Regards, jh
Made some edits to my earlier post -- jh