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
Arpita NayakArpita Nayak 

Read only field

Hi Guys,
How to make a field read only in visualforce page.
Tavva Sai KrishnaTavva Sai Krishna
Hi Arpita,

You can use output field tag instead of using inputfield tag, which will display the field as readonly in visualforce page.

let me know if you have any questions.

Regards,
Sai Krishna Tavva
Amit Chaudhary 8Amit Chaudhary 8
Hi Arpita Nayak ,

You can try the <apex:outputField tag for same.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_outputField.htm

Let us know if this will help you

Thanks
Amit Chaudhary
JyothsnaJyothsna (Salesforce Developers) 
Hi Arpita,

To make this field read-only, Click on

Setup ---> Customize ---> Objects ---> Page Layouts ---> Edit the page layout ---> Select the field you want to make read-only ---> Click on 'Properties' of the field(an icon to the right end of field) ---> Here you will get a checkbox to make the field read only.

Another way to make the field read only is -

Setup ---> Customize ---> Objects ---> Fields ---> Click on the field you want to make read-only ---> Click on button 'Set field-level security' ---> here make the field read only for the profiles you want.

note: Formula fields are always calculated, and therefore always read-only.

Hope this helps you!
Best Regards,
Jyothsna
 
Arpita NayakArpita Nayak
Thanx to all for reply,my requirement is this
User-added image
DebasisDebasis
Hi Arpita,

if you are usng Apex:inputtext in your visualforce page then use below code 
<apex:inputText value="{!Account.Name}" html-readonly="true" />

if you are using apex:inputfield then it will redirect from the Fieldlevel security of that field
go to Setup ---> Customize ---> Objects ---> Fields ---> Click on the field you want to make read-only ---> Click on button 'Set field-level security' ---> here make the field read only for the profiles you want.
Also still you can disable that field using disabled="true"

if you are displaying the field in detail mode then you can use outputField 
 
<apex:outputField value="{!Account.Name}" />

Also you can use Javascript to make any input field as readonly
document.getElementById("FieldId").readOnly = true;

Please do let me know if it helps you.  

Thanks,
Debasis
Arpita NayakArpita Nayak
Hi Debasis,
i have tried but error coming .please check once.

User-added image
Tavva Sai KrishnaTavva Sai Krishna
Hi Arpita,

You have to use the <apex:page> as the starting tag. inside the <apex:page> you need to define the <apex:form> tag. hope this link will give you more detail about this tag.

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_page.htm
 
<apex:page controller="MoveStudent" sidebar="false" showheader="false">
<apex:form>
//write your code
</apex:form>
</apex:page>
Also above code is the markup which you have to modify the code 

Regards,
Sai Krishna Tavva.
Arpita NayakArpita Nayak
Thanx for your reply Krishna.Now its working but the read only field is not coming in VF page
Arpita NayakArpita Nayak
<apex:page controller="Movestudent" sidebar="false" showHeader="false">
<apex:form >
 <apex:pageBlock >
 <apex:pageBlockTable value="{!students}" var="a" cellPadding="4" border="1">
 <inputText="From Class" readonly="true"/>
 <apex:column value="{!a.Name}"/> 
 <apex:column value="{!a.Roll_Number__c}"/> 
  <apex:column value="{!a.DOB__c }"/> 
  </apex:pageBlockTable>
 </apex:pageBlock>
 </apex:form>
  </apex:page>
Amit Chaudhary 8Amit Chaudhary 8
Please update your code like below
<apex:page controller="Movestudent" sidebar="false" showHeader="false">
	<apex:form >
		<apex:pageBlock >
			<apex:pageBlockTable value="{!students}" var="a" cellPadding="4" border="1">
				<apex:column>
					<!- Please add your field here -->
					<inputText="From Class" readonly="true"/>
				</apex:column>
				<apex:column value="{!a.Name}"/> 
				<apex:column value="{!a.Roll_Number__c}"/> 
				<apex:column value="{!a.DOB__c }"/> 
			</apex:pageBlockTable>
		</apex:pageBlock>
	</apex:form>
</apex:page>

 
DebasisDebasis
Hi Arpita,

in your previous code you git error because youe apex:form tag is on top of the apex:page tag, apex:page tag should be the top most markup.

try this below code 
apex:page controller="Movestudent" sidebar="false" showHeader="false">
<apex:form >
 <apex:pageBlock >
 
 <apex:pageBlockTable value="{!students}" var="a" cellPadding="4" border="1">
<apex:column>
    <apex:inputtext value="{!inputvalue}" html-readonly="true"/><!-- inputvalue replace as your field name-->
</apex:column>
 <apex:column value="{!a.Name}"/> 
 <apex:column value="{!a.type}"/> 
  <apex:column value="{!a.rating}"/> 
  </apex:pageBlockTable>
 </apex:pageBlock>
 </apex:form>
  </apex:page>

 
Arpita NayakArpita Nayak
Hi Debasis ,
Still its giving error

User-added image
DebasisDebasis
Hi Arpita,

Please use your field name instead of inputValue in this line 
<apex:inputtext value="{!inputvalue}" html-readonly="true"/><!-- inputvalue replace as your field name-->

iyou can use your controller variable/property or field api name in place of inputvalue.
<apex:page controller="Movestudent" sidebar="false" showHeader="false">
<apex:form >
 <apex:pageBlock >
 
 <apex:pageBlockTable value="{!students}" var="a" cellPadding="4" border="1">
<apex:column>
    <apex:inputtext value="{!inputvalue}" html-readonly="true"/><!-- inputvalue replace as your field name-->
</apex:column>
 <apex:column value="{!a.Name}"/> 
 <apex:column value="{!a.type}"/> 
  <apex:column value="{!a.rating}"/> 
  </apex:pageBlockTable>
 </apex:pageBlock>
 </apex:form>
  </apex:page>


Thanks,
Debasis
Arpita NayakArpita Nayak
Hi Debasis,
I forgot to change that field name,However after changing the field name still the read only field not coming.User-added image
DebasisDebasis
Hi Arpita,

it would be great if you can post your visualforce code and controller code and i can make appropriate changes and will revert back toyou. from your above reply, there from_class__c is not a property in controller. I think you should use {!a.from_class__c} instead of only {!from_class__C}


please post code i will take a look.
Arpita NayakArpita Nayak

Error: Invalid field type for SObject Student__c
VF page
<apex:page controller="Movestudent" sidebar="false" showHeader="false">
<apex:form >
 <apex:pageBlock >
 
 <apex:pageBlockTable value="{!students}" var="a" cellPadding="4" border="1">
<apex:column>
    <apex:inputtext value="{!a.From_Class__c}" html-readonly="true"/><!-- inputvalue replace as your field name-->
</apex:column>
 <apex:column value="{!a.Name}"/> 
 <apex:column value="{!a.type}"/> 
  <apex:column value="{!a.DOB__c}"/> 
  </apex:pageBlockTable>
 </apex:pageBlock>
 </apex:form>
  </apex:page>

Apex class

public class Movestudent{
List<Student__c> students=[select Name,Roll_Number__c,DOB__c,From_Class__c from Student__c];
public List<Student__c > getstudents(){
return students;
}
}