Hi again,
All about jQuery these days.This is such a powerful language to do a lot of cool things on SharePoint!
After my blogpost about hiding fields in the Editform in SharePoint, I got some questions on how to hide fields in the Dispform too.
So let us check out what happens in SharePoint and how you can use Jquery to hide these fields.
Editform / Newform
SharePoint output:
<tr> <td nowrap="true" valign="top" width="190px" class="ms-formlabel" > <h3 class="ms-standardheader"> <nobr>FIELD NAME</nobr> </h3> </td > <td valign="top" class="ms-formbody"> <!-- FieldName="FIELD NAME" FieldInternalName="FIELD INTERNAL NAME" FieldType="SPFieldText" --> <span dir="none"> <input name="Value$TextField" type="text" value="VALUE" maxlength="255" id="ID_TextField" title="FIELD TITLE" class="ms-long ms-spellcheck-true" /> <br /> </span> </td> </tr>
We are going to check the code until we find a NOBR tag that contains our value. Next we are going to the closest table row and hide that.
You can get the field name via the Nobr tag enclosing the field title:
$('nobr:contains("FIELD NAME")').closest('tr').hide();
Dispform
SharePoint output:
<TR> <TD nowrap="true" valign="top" width="165px" class="ms-formlabel"> <H3 class="ms-standardheader"> <a name="SPBookmark_FIELDNAME"> </a> FIELD NAME </H3> </TD> <TD valign="top" class="ms-formbody" width="450px" ID="SPFieldText"> <!-- FieldName="FIELD NAME" FieldInternalName="FIELD NAME" FieldType="SPFieldText" --> FIELD VALUE; </TD> <TR>
Here we have our Field name enclosed in the H3 tag.
$('h3:contains("FIELD NAME")').closest('tr').hide();
Or if you want to get the value of the field:
Var sField1 = $('h3:contains("Field1")').closest('td').next('td').text();
There's a good jQuery plugin to manipulate SharePoint forms: http://jpoint.codeplex.com/
I've used it on a few projects and it works great on 2007 and 2010.