Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

i have a field that i want to make not editable for the users. its a field of type text.

I have a read about doing it with javascript and content editor webbpart, but i want to do it programmatically because the field is part of my Feature.

i have tried this code, but it hides the field in forms view.

SPList list = web.lists["caseslist"]; 
SPField field = list.Fields.GetField("casenumbers"); 
field.ReadOnlyField = true; 
field.ShowInDisplayForm = true; 
field.ShowInEditForm = true; 
field.ShowInNewForm = true; 

what are iam doing wrong, why does this code hide the field in the forms? Iam not sure but is it possible to make a field "non editable" programmatically?

share|improve this question

2 Answers 2

If you make field readonly it will not be displayed on edit or new forms. You can do it with custom form only. There are not needs to use JS-code, you can do it with xslt but in custom form only. But you can deploy this form with your feature.

share|improve this answer
Thans for the reply. i solved it with using javascript, it works well. I added a content editor webpart in the different forms and added javascript to that cewp. But have do i hide fields of type Person or Group with javascript?? it doesnt work with my code. And something more that i cant find information about, is it possible to add my javascript code in a feature and load it on the forms when the feature is activated?? –  David Oct 7 '12 at 18:44
Yes, you can hide any field with javascript, person or group as well. Just hide table rows with such fields. Also I can recommend you to use Forms Designer tool: spform.com. It allows you to make fields readonly on edit and new forms. As about deploying your form, yes, you can add your form into the feature. You can define template for your list with links to your custom form and deploy custom form page as module. –  Dmitry Kozlov Oct 7 '12 at 19:26
i cant figure out how to hide a person or group field with javascrit. because i have the same js code that i use for text field, multipletext field, chooice field. all works fine but not for a Person or Group field. But i dont want to make a custom form, i want to use the built in sharepoint form. in that case is it possible to add the javascript to the feature and activate it that way? –  David Oct 7 '12 at 19:58
Could you publish js-code you use to hide other fields? You already created custom form since you added CEWP web part. You have to deploy page with feature, not only javascript-code. –  Dmitry Kozlov Oct 8 '12 at 5:51
    My code: 

        <SCRIPT language=javascript> 
        function DisableField(title) {
        for(var i = 0; i < document.all.length; i++) {
        var el = document.all[i]; 
        if(el.title == title) 
        el.disabled = true; 


As mentioned this code works for my fields, except the Person or Group field.

Sorry but i dont understand how to package this and deploy it with my feature?

thanks for you replys its really helpful.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.