2

I have a series of fields that I would like NOT to appear in my list dispForm.aspx. So when a user creates a new list item if these fields are unpopulated the do not appear DispForm.aspx but I still need the EditForm.aspx to show all fields.

I know OOB I am able to hide the list item under content type...this is not what i am looking to achieve.

Is there a way to achieve this with calculated values? ISBLANK (not familiar with the syntax)

Is anyone aware of a solution.

Have tried caml queries such as listed in other posts

"<View><Query><Where><IsNotNull><FieldRef Name="ContentType"/></IsNotNull></Where></Query></View>"

As well as

"<View><Query><Where><Eq><FieldRef Name="ContentType" /><Value Type="Text">Document</Value></Eq><And><IsNotNull><FieldRef Name="ContentType" /></IsNotNull><Neq><FieldRef Name="ContentType" /><Value Type="Text">Document</Value></Neq> </And> </Where></Query></View>"

3 Answers 3

1

Insert the following js-code into your DispForm.aspx with SharePoint Designer:

<script type="text/javascript">
  $(function() {
    $.each($('td.ms-formbody'), function() {
      if (!$(this).text().replace(/\xA0/,' ').trim()) {
        $(this).closest('tr').hide();
      }
    });
  });
</script>

You also have to included JQuery-library into DispForm.aspx or master-page.

12
  • Dmitry - thanks heaps for the code snippet - looks just to be just what I need. I will need sum assitance as to where to load the min.js. thanks
    – garvon-77
    Jun 21, 2013 at 3:52
  • I have added the above script and the script link tag to the DispForm.aspx - I do not see any changes - Do you think it is a misplacement of the script or the link - script link reads as follows: <SharePoint:ScriptLink runat="server" Name="/SiteAssets/js/jquery-1.10.1-min.js" Localizable="false"/>
    – garvon-77
    Jun 24, 2013 at 22:20
  • Hello, please, try to include jquery-library by using simple html tag: <script language="text/javascript" src="/SiteAssets/js/jquery-1.10.1-min.js" ></script> Jun 25, 2013 at 13:17
  • Thanks Dmitry - still not have any luck with the solution - not hiding any empty fields. Any other suggestions?
    – garvon-77
    Jun 26, 2013 at 1:56
  • Which version of SharePoint do you use? Jun 26, 2013 at 11:59
0

You can write a httpmodule, and do something like this:

 private void context_PreRequestHandlerExecute(object sender, EventArgs e)
 {
            Page handler = (Page) HttpContext.Current.Handler;
            string rawUrl = HttpContext.Current.Request.RawUrl;
            if (rawUrl.Contains("/DispForm.aspx?"))
            {                
                handler.Load += new EventHandler(this.page_Load);//remove those fileds you want to hide in page_Load function.
            }
  }
2
  • Thanks Raymond - unable to do at this time - do not have a VS project setup (VS installed for that matter). I was hoping to achieve this with caml, jquery or calculated value. Any other suggestions?
    – garvon-77
    Jun 20, 2013 at 5:31
  • I have encountered a problem with my request. The series of fields I do not want to display are not in the DispForm.aspx but in the modal dialog - I was under the impression the DispForm.aspx drove the modal dialog output. I dont think this is correct. Can someone advise please.
    – garvon-77
    Jun 24, 2013 at 22:47
0

Yes you can do similar with jQuery. Using SPD you can edit the lists DisplayForm.aspx and add in the script you need to hide the field if it is empty.

Getting the correct field can be a bit of a challenge as it is a dynamically created form - I usually use the attribute "title" which contains the display version of the column name. The downside to this is that if you change the display name you need to change your script. Click F12 in IE to get developer mode and you will be able to see the structure of the HTML in the form.

EDIT: Code snippet as requested

$("input[title='ExternalColumnName']").parents("tr:first").hide();

You will need to check what sort of input/textarea/select etc your fields are and then use the column name to identify them.

1
  • I have updated my answer with a snippet as requested. This is using jQuery so you will also need the jQuery library active though you could also convert it to javascript if you prefer. Jun 21, 2013 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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