function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deepak ChouhanDeepak Chouhan 

Custom validation in Visualforce Page on Edit button

Hi,
   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:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_outputText.htm
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>
<style>
    .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;}
   
  </style>
  
  <script>
  function validateInsertUpdate()
    {
        var valid1 = true;
       
        if($('.company').val() == '')
        {
            valid1 = false;
            $('#company').show();   
        }
        else
        {
            valid1 = true;
            $('#company').hide(); 
        }
        
        }
        
        if(valid1 == true)
        {
            //Call the Action method via Action function
        }
        </script>
<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>                             
                        </apex:selectList>
                        <div id="company" class="error_div"><span>Error:</span><p>You must enter a value</p></div> 
                    </div>                       
                </apex:outputPanel>
            
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
        <apex:pageBlockButtons >
            <apex:commandButton value="Ok" onclick="validateInsertUpdate();" reRender="nothing"/>
        </apex:pageBlockButtons>
        <apex:inputHidden id="nothing"/>
    </apex:pageBlock>
    </apex:form>
</apex:page>

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.