+ Start a Discussion
Deepak ChouhanDeepak Chouhan 

Custom validation in Visualforce Page on Edit button

   I have created visualforce page with standard object (account). my question is whenever i click the edit button on detail page i want to disabled some required field and user can't edit those field.
pls help me out.
SonamSonam (Salesforce Developers) 
You can use the outputtext tag to display the value of fields you do not want users to be able to edit:
Deepak ChouhanDeepak Chouhan
Hi Sonam,

Actually i am using some input field on VF page i.e. <apex:inputText id="acc" value="{!account.Name}" title="Name" />
User create new record but can't edit. VF page link to edit button. whenever user click edit button this field showing read-only mode or disabled.
Chamil MadusankaChamil Madusanka
<apex:page sidebar="false">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    .error_div {display:none;}
    .error_div {height: 15px; position: relative; width: 100%; color:#D74C3B;}
    .error_div span{ left: 0; position: absolute; top: 0; font-weight:bold;}
    .error_div p { left: 35px; margin: 0; position: absolute; top: 0;}
  function validateInsertUpdate()
        var valid1 = true;
        if($('.company').val() == '')
            valid1 = false;
            valid1 = true;
        if(valid1 == true)
            //Call the Action method via Action function
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Company"></apex:outputLabel>
                <apex:outputPanel styleClass="required_span" >
                    <div class="requiredInput">
                        <div class="requiredBlock"></div>                       
                        <apex:selectList styleClass="company" size="1" >
                            <apex:selectOption itemLabel="None" itemValue=""></apex:selectOption> 
                            <apex:selectOption itemLabel="Test1" itemValue="Test1"></apex:selectOption>
                            <apex:selectOption itemLabel="Test2" itemValue="Test2"></apex:selectOption>
                            <apex:selectOption itemLabel="Test3" itemValue="Test3"></apex:selectOption>                             
                        <div id="company" class="error_div"><span>Error:</span><p>You must enter a value</p></div> 
        <apex:pageBlockButtons >
            <apex:commandButton value="Ok" onclick="validateInsertUpdate();" reRender="nothing"/>
        <apex:inputHidden id="nothing"/>

Try this code.
Deepak ChouhanDeepak Chouhan
Hi Chamil,
This validation working on click event but i want to working with page load event. when user  click edit button open override VF page. this validtion perform page load time.
Chamil MadusankaChamil Madusanka
You can convert this example to your scenario. I gave the path.