none
Make some fields read only in EditForm.aspx in List template RRS feed

  • Question

  • In my SharePoint VS 2010 Empty project, I added a list definition template and used schema.xml, elements.xml to create a list template where I created a new content type and associated those fields to that list template.

    Alo I need to make some of the fields not editable (readonly) on editform.aspx. How can I do this in the same solution file or do I need to use client side script to achieve this? Please suggest a best solution for this.

    Thanks in advance.

     

    • Edited by AparnaT Monday, January 9, 2012 4:02 PM
    Monday, January 9, 2012 4:01 PM

Answers

  • Is list created using a feature or are you manually creating it from your custom template?

    If it is created using a fetaure, you can write the code in feature receiver to set the specific fields to readonly.


    Priyanka
    Tuesday, January 10, 2012 2:31 PM
  • Hi, from the javascript also you can hide fields or make them read only.

    <script type="text/javascript">
    
    function DisableReadOnly()
    {
    // find all the elements with tag Name as INPUT
    var elements=document.body.getElementsByTagName("INPUT");
    // loop through all the elements till we find an element with type text and title as name of our field
    for (index=0; index < elements.length;++index)
    {
    if(elements[index].type=="text")
    {
    if(elements[index].title=="Address") //Field name
    {
    elements[index].readOnly=true;
    }
    }
    }
    }
    _spBodyOnLoadFunctionNames.push("DisableReadOnly()");</script>



    Anil
    Tuesday, January 10, 2012 3:19 PM

All replies

  • You can set the ReadOnly property to True. But with this, i think you may not be able to edit this field on the New Item form too.. which could cause issue.

      <Field ID="{060E50AC-E9C1-4D3C-B1F9-DE0BCAC300F6}"
             Name="Amount"
             Readonly="TRUE"
             Decimals="2"
             Min="0"
             Required="FALSE"
             Group="Financial Columns" />

    Alternatively, you can hide the field ( on the edit page only) by setting ShowInEditForm property to "FALSE" in <field> element. You can still view this field's value in List View or via the view properties.

    <Field ID="{060E50AC-E9C1-4D3C-B1F9-DE0BCAC300F6}"
    Name="Amount"
    Decimals="2"
    ShowInEditForm = "FALSE"
    Min="0"
    Required="FALSE"
    Group="Financial Columns" />

    Refer - http://msdn.microsoft.com/en-us/library/aa979575.aspx


    Priyanka
    • Edited by priyanka8275 Tuesday, January 10, 2012 10:14 AM edited the text
    Tuesday, January 10, 2012 10:10 AM
  • you can do this by using SharePoint Designer 2010 by make a copy from EditForm.aspx then set the property  ControlMode to "Display" for each control you want it to be read only  for= example

    <SharePoint:FormField runat="server" id="ff1{$Pos}" ControlMode="Display" .............../>
    

    After that save changes on new EditForm.aspx but do not forget to make it set it as a Default Edit Form of your list

    Hope that help.

    Regards.


    Ahmed Naji SharePoint Geek
    MCP|MCTS
    My Blog | DotnetFinder
    Please click "Marked As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you
    Tuesday, January 10, 2012 10:24 AM
  • @alnaji- thanks for the reply. But we need to do this after the list has been created. I want the solution wherein those fields should be set to read-only when the list is being created , as that list is created from my custom list template.

      

     

     

     

    Tuesday, January 10, 2012 2:05 PM
  • Is list created using a feature or are you manually creating it from your custom template?

    If it is created using a fetaure, you can write the code in feature receiver to set the specific fields to readonly.


    Priyanka
    Tuesday, January 10, 2012 2:31 PM
  • @Priyanka- yes it is created using a feature. And I am trying your solution and let you know if that works.

    Thank you.

    Tuesday, January 10, 2012 2:44 PM
  • Hi, from the javascript also you can hide fields or make them read only.

    <script type="text/javascript">
    
    function DisableReadOnly()
    {
    // find all the elements with tag Name as INPUT
    var elements=document.body.getElementsByTagName("INPUT");
    // loop through all the elements till we find an element with type text and title as name of our field
    for (index=0; index < elements.length;++index)
    {
    if(elements[index].type=="text")
    {
    if(elements[index].title=="Address") //Field name
    {
    elements[index].readOnly=true;
    }
    }
    }
    }
    _spBodyOnLoadFunctionNames.push("DisableReadOnly()");</script>



    Anil
    Tuesday, January 10, 2012 3:19 PM
  • Good stuff, everyone! I have tried setting ControlMode to "Display" for a field that I want to be read-only on my customized EditForm. However, the result is that the field does not appear on the form at all now!

    Anyone have insight into why this is happening?

    I am using SharePpoint Designer 2010 and SharePoint 2010. The field is a simple text input field. This is the code I used:

    <SharePoint:FormField runat="server" id="ff10{$Pos}" ControlMode="Display" FieldName="EPMS_x0020_Charge_x0020_Bucket" __designer:bind="{ddwrt:DataBind('u',concat('ff10',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@EPMS_x0020_Charge_x0020_Bucket')}"/>

    Thanks!

    Leon


    Leon Bryant

    Wednesday, March 6, 2013 9:44 PM