How to customize rendering of SharePoint list form fields - Part 1

While SharePoint offers great flexibility to users for quickly creating custom lists in various forms, flexibility of forms and fields rendered within is fairly limited on WSS/MOSS UI. In this series, I aim to share some of my findings and, perhaps, come up with wish-list for "SharePoint 2009"!

There are various types of form customization that we often need to make. For example:

  1. Show/Hide specific Fields on a form type.
  2. Show field in read-only mode on Edit form. Not allowing user to edit once field is populated while creating item.
  3. Allow dynamic behavior for a form regarding above, based on users credentials/rights.
  4. When a field is read-only, allowing user to override by clicking a link and letting him enter value.

1. Show/Hide a Field

When using content-types, a user can choose to show/hide a field from forms on content-type edit page. When creating custom solutions, or with list definitions, one can decide with following attributes in Field element to show/hide a form field in New, Edit, or Display form. Same can either be done declaratively in your element xml, or through object model updates to list/field schema. In case you are stuck in a environment where you do not have privilege of making custom deployments, and do have access to your site via web-services then you can use Lists.asmx service to send updates to an existing list schema. Following are 6 example options:

Field Element:

<Field   
    ...   
    ShowInDisplayForm = "TRUE" | "FALSE"   
    ShowInEditForm = "TRUE" | "FALSE"   
    ShowInNewForm = "TRUE" | "FALSE"   
    .../>

FieldRef Element:

<FieldRef   
    ... 
    ShowInDisplayForm="TRUE" | "FALSE"   
    ShowInEditForm="TRUE" | "FALSE"   
    ShowInNewForm="TRUE" | "FALSE"></FieldRef>

Object Model:

instance.ShowInEditForm = value;

Using SharePoint Designer:

You can copy existing form-pages and create new one. Remove existing form web-part and create a new ListForm web-part, with flexibility of showing/hiding fields of choice. Be mindful of not unghosting your pages, for the sake of long term hygiene of your site and forms. Details of steps can be browsed here, and here.

Client-side JavaScript in a Content Editor Web-Part (CEWP):

You can also include CEWP in your ghosted Form pages, without unghosting them, and add JavaScript that will hide controls on client-side based on your set configuration in web-part. Goodness about web-part approach is that it allows utilizing audience set to a web-part to show/hide varying controls per audience. Clever details can best be seen at Clever Workarounds.

Custom Rendering Template

Apart from above, there is a hidden gem in CONTROLTEMPLATES folder, DefaultTemplates.ascx. All of SharePoint forms, be it lists or libraries, are rendered based on RenderingTemplate's that reside in this folder. So if you open the file, you'll notice there is plethora of templates there. Good thing is that we do not need to replace the markup in system files, and they can instead be overridden by creating your own ASCX file and placing the same rendering template (with same ID) in yours. At execution time, your will be preferred and hence will override any system functionality. Having said that, we are interested in a RenderingTemplate named ListForm. This template is responsible for all your list forms (New/Edit/Display). Within the template you'll notice a control ListFieldIterator, which is responsible for iterating through all field at runtime and has a method in its class IsFieldExcluded() which we can use to decide which fields to show on which form at runtime. In the sample below, I'm showing replacement of system control with custom one, <eJugnoo:FormFieldIterator/>:

<%@ Register TagPrefix="eJugnoo" Assembly="eJugnoo.SharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b5eacb14abbc6805" namespace="eJugnoo.SharePoint.FormSettings" %>

<SharePoint:RenderingTemplate ID="ListForm" runat="server">
    <Template>
        <SPAN id='part1'>
            <SharePoint:InformationBar runat="server"/>
            <wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbltop" RightButtonSeparator="&nbsp;" runat="server">
                    <Template_RightButtons>
                        <SharePoint:NextPageButton runat="server"/>
                        <SharePoint:SaveButton runat="server"/>
                        <SharePoint:GoBackButton runat="server"/>
                    </Template_RightButtons>
            </wssuc:ToolBar>
            <SharePoint:FormToolBar runat="server"/>
            <TABLE class="ms-formtable" style="margin-top: 8px;" border=0 cellpadding=0 cellspacing=0 width=100%&gt;
            &lt;SharePoint:ChangeContentType runat="server"/>
            <SharePoint:FolderFormFields runat="server"/>
            <eJugnoo:FormFieldIterator runat="server"/>
            <SharePoint:ApprovalStatus runat="server"/>
            <SharePoint:FormComponent TemplateName="AttachmentRows" runat="server"/>
            </TABLE>
            <table cellpadding=0 cellspacing=0 width=100%&gt;&lt;tr><td class="ms-formline"><IMG SRC="/_layouts/images/blank.gif" width=1 height=1 alt=""></td></tr></table>
            <TABLE cellpadding=0 cellspacing=0 width=100% style="padding-top: 7px"><tr><td width=100%&gt;
            &lt;SharePoint:ItemHiddenVersion runat="server"/>
            <SharePoint:ParentInformationField runat="server"/>
            <SharePoint:InitContentType runat="server"/>
            <wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbl" RightButtonSeparator="&nbsp;" runat="server">
                    <Template_Buttons>
                        <SharePoint:CreatedModifiedInfo runat="server"/>
                    </Template_Buttons>
                    <Template_RightButtons>
                        <SharePoint:SaveButton runat="server"/>
                        <SharePoint:GoBackButton runat="server"/>
                    </Template_RightButtons>
            </wssuc:ToolBar>
            </td></tr></TABLE>
        </SPAN>
        <SharePoint:AttachmentUpload runat="server"/>
    </Template>
</SharePoint:RenderingTemplate>

You can use above in your custom Feature, apply custom logic to decide which field to show/hide. Above can also be part of a generic solution that is available for all lists, by providing a configuration page (_layouts) and custom actions link on list settings.

Hope above gives you a good idea about various options available to meet form customization needs. Sometime soon, I'm going to share sample code on codeplex that simply provides users a UI to configure form visibility for any list instead of depending on developers each time they need a form customization.

Watch this space for updates...

-- Sharad

UPDATE (July 29, 2008): I have published a follow-up post to my preferred server-side approach to Form Customizations.
http://weblogs.asp.net/sharadkumar/archive/2008/07/28/how-to-customize-sharepoint-forms-part-2.aspx

40 Comments

  • with the third solution (Custom Rendering Template), once you've deployed the overriding ascx file, where do you go to see the changes you mentioned? (you mentioned..."You can use above in your custom Feature, apply custom logic to decide which field to show/hide" what does this mean? could you provide an example?)

    thanks,
    t

  • Tom, all you have to do is:

    Create a Feature that includes your ASCX, an app-page with code-behind for capturing which fields to hide/show. Save the information in PropertyBag of root-folder of current list. Use this propertybag values for rendering fields at runtime with a custom class, FormFieldIterator, that inherits from Microsoft.SharePoint.Webcontrols.ListFieldIterator. Override the implementation of member IsFieldExcluded() in your calls based on values saved in PropertyBag for current list reg: which field to show/hide. Not you'll have to implement a switch for 3 ControlMode's, New/Edit/Display, so that you can implement variance of show/hide based on which form you are currently rendering.

    Does that makes sense?

    -- Sharad

  • I would like to hide fields based on the refering view, is this possible?

  • Pierre,
    Checkout my follow-up post on better server-side possibilities with Forms. You can download the bits and use them right away.
    Regarding views-based conditional Forms - Yes, you can achieve that by saving such conditional config in lists property-bag. Enhancing UI to input such settings, as in my post. Then on the fly setting values in IsFieldIncluded() for each field you want to show/hide.
    In fact, I'm considering enhancing the implementation to support conditional forms relative to values in same item. Not sure, if Views-based conditions is something I'd want to do though.
    Perhaps, if you'd give use-case example - I'd be able to relate to more generic usage.
    Thanks.
    -- Sharad

  • Hello
    I have installed the web application feature you created to manage forms and it is a great feature. i am having some issues with one list that does not use your feature. For some reasons, the field description will not display for this list or any other lists on my site. Would you have any idea why?

    thanks

  • is it possible to display (or hide) one field in the list based on users' response to earlier fields in the same list? i.e. have a dynamic list? I am using MOSS and SharePoint Designer.

  • Hi

    I am interested in hiding a field in the list in edit mode based on what the user input to another field during creation. Is this possible without using SharePoint designer?

    Example:
    During lList item creation:
    Field 1 = false
    Field 2 = "hello"

    During editing, I want to show Field 2 only when Field 1 was set to true.

    Thanks


  • Try this too,

    http://sarangasl.blogspot.com/2009/10/hide-column-in-edit-new-or-display-mode.html

  • If I need to delete the left column (Title, Body, Expires text) of a display form (dispform.aspx) for a news item, is this done by overriding the formFieldIterator?
    Thanks in advance.

  • Hi,

    I have created a folder content type with custom columns. Ehile creating a new folder of this type, a default "Name" field is displayed along with the other custom columns. How can this "Name" field be hidden\removed\renamed?

    Please help!!

    Thanks

  • Hi

    We would like to see the field description (tip) on the DispForm.aspx form as well. Do you know how this can be accomplished?

    People are using Custom lists as questionnaires and they are adding valuable information about the question in the field description (tip) field. When they later view the answers of the questionnaires, they would like to see the full descriptions (tips) of the fields. At the moment, they have to go into the edit view all the time.

    Thanks for the help.

  • How to customize rendering of sharepoint list form fields part 1.. Bang-up :)

  • I would like to create a new form based on schema then customize it as separate title blocks.how can i will achieve this one using form rendering ?

  • superb post!! keep working this great stuff

  • an seinem etwas abändern möchte, der beginnt sich gegenwärtig
    zu werden, das eins sanfte Methode mit Globuli zum eine gute Alternative zu Diäten ist.
    Der Weg ist , denn jeder ist separat. Um optimale Erfolge zu erzielen,
    gehört wahrhaft eine Ernährungsumstellung nun, aber
    jeder Körper reagiert anders und gibt es ja hinter Stoffwechsel manche
    Globulin zum An gewicht verlieren.. Um unter anderem harmlos können, kann
    man mit Globuli zum ein wertvolles und sinnvolles Mittel benutzen.

    Doch eines sollte vorerst erwähnt werden. Bei Globulin
    zum handelt es zigeunern nicht um Diätpillen sondern man
    bedient der Wirkstoffe der Natur. Die zum zu tun sein den Organismus auf sanfte Formgebung rein seinem „Tun“ unterstützen.
    Die Erfahrungen von Anwendern von Globulin zum Abspecken dabei gute Erfolge,
    obgleich es zu diesem zweck keine wissenschaftlichen Belege gibt.

    Schon immer holten aber die Leute Hilfe aus der Natur, wie zum
    Globulin zum . zur Linderung gegen äußere Verletzungen, gegen Unruhen oder
    eben beim Abspecken, die Wirkstoffe, die aus der Natur ,
    scheinen eine besondere Stärke ferner sind überaus beliebt.
    Insbesondere bei der Gewichtsreduzierung können zum helfen.
    So wird durch Streukügelchen zum Abnehmen Globuli zum abnehmen

  • Pretty section of content. I just stumbled upon your weblog and
    in accession capital to assert that I acquire in fact
    enjoyed account your blog posts. Anyway I will be subscribing to your augment and even I achievement you access consistently fast.

  • Unquestionably believe that which you stated. Your favorite justification appeared to
    be on the internet the easiest thing to be aware of. I say to you, I certainly get annoyed while people consider worries that they just do not know about.

    You managed to hit the nail upon the top as well as defined out the whole thing without
    having side effect , people can take a signal. Will probably
    be back to get more. Thanks

  • Its not my first time to pay a quick visit this site, i am browsing this web site dailly and get good information from
    here everyday.

  • i have very superficial (but noticeable) scars on my provide
    through to fall out of the forest and they also make me look like i personal damage!
    ! (i dont) i want to get rid of them as soon as possible
    because they are embarassing. i've been making use of Bio Oil and also i've simply noticed a small improvement.
    how much time will it consider to enable them to fade?
    if Bio Oil don't perform, what is going to?

  • Excellent goods from you, man. I've understand your stuff previous to and you're
    just too great. I actually like what you've acquired here, really like what you're stating
    and the way in which you say it. You make it entertaining and you still take care of to keep it sensible.
    I can not wait to read much more from you. This is actually
    a tremendous web site.

  • Wow, incredible blog layout! How long have you been blogging for?
    you make blogging look easy. The overall look of your site is fantastic,
    as well as the content!

  • This piece of writing offers clear idea in support
    of the new people of blogging, that really how to do blogging and site-building.

  • I know this if off topic but I'm looking into starting my own weblog and was wondering what all is required to get setup? I'm
    assuming having a blog like yours would cost a pretty penny?
    I'm not very web smart so I'm not 100% sure. Any tips or advice would be greatly appreciated. Cheers

  • Peculiar article, exactly what I needed.

  • Link exchange is nothing else but it is only placing the other
    person's webpage link on your page at suitable place and other person will also do similar for you.

  • I believe this is among the most important info for me.
    And i'm satisfied reading your article. But should commentary on few basic issues, The website style is great, the articles is really nice : D. Good task, cheers

  • Simply want to say your article is as amazing.
    The clearness in your publish is simply great and
    that i can think you are knowledgeable in this subject.
    Fine together with your permission let me to take hold of your RSS feed to keep up to date with impending post.
    Thanks one million and please keep up the rewarding work.

  • Wow! After all I got a blog from where I be capable of actually
    obtain valuable data concerning my study and knowledge.

    Solar Pool Pump

  • This article will assist the internet visitors for creating new website
    or even a weblog from start to end.

  • I like your content rich information! Wonderful insight pertaining to assualt part 2,
    thanks so much for sharing.

  • What a data of un-ambiguity and preserveness of precious familiarity about unpredicted feelings.

  • I visited many websites but the audio quality
    for audio songs current at this web site is really marvelous.

  • I loved as much as you'll receive carried out right here. The sketch is attractive, your authored material stylish. nonetheless, you command get got an shakiness over that you wish be delivering the following. unwell unquestionably come further formerly again since exactly the same nearly very often inside case you shield this increase.

  • Everything typed was very reasonable. However, think on this, what if you
    added a little content? I mean, I don't wish to tell you how to run your website, but suppose you added something that grabbed a person's attention?
    I mean How to customize rendering of SharePoint list form fields - Part 1 - Sharad Kumar is kinda boring.
    You might peek at Yahoo's front page and see how they create post titles to get viewers to click. You might add a video or a pic or two to get readers excited about what you've got to say.
    In my opinion, it would bring your posts a little bit more interesting.

  • Great delivery. Solid arguments. Keep up the
    amazing effort.

  • What's up every one, here every person is sharing these knowledge, so it's nice to read this website, and
    I used to pay a visit this web site everyday.

  • Hi there mates, its wonderful piece of writing about tutoringand completely defined,
    keep it up all the time.

  • This post is actually a fastidious one it helps new net viewers, who are wishing
    for blogging.

  • Good day! I just wish to give you a huge thumbs up for the great information you have got right here
    on this post. I am returning to your web site for more soon.

  • You can certainly see your expertise within the work you write.
    The sector hopes for even more passionate writers such as you who are not afraid to say how they believe.
    All the time follow your heart.

Comments have been disabled for this content.