7/25/2009

SharePoint: Change the “Add New” message for a web part

 

A version of this article for SharePoint 2010 is here:
http://techtrainingnotes.blogspot.com/2010/08/sharepoint-2010-change-add-new-item-and.html

 

 

How to change from “Add new announcement”:

   image

to “Click here to add team news”:

   image

 

ID’s used by web parts

Each web part has a different ID. You will need to modify the following code with the needed ID. Note that some lists use the same ID, like Documents and Wikis.

 

Web Part Default message ID for “document.all” in the code below
Announcements Add new announcement "Add new announcement"
Links Add new link "idHomePageNewLink" 
Calendar Add new event "idHomePageNewEvent"
Picture Library Add new picture "idAddPicture"
KPI List Add new item "idAddNewItem"
Tasks Add new item "idAddNewTask"  *
Project Tasks Add new item "idAddNewTask"  *
Document Library Add new document "idAddNewDoc"   *
Wiki Add new Wiki page "idAddNewDoc"   *
Survey Respond to this survey "idNewSurveyResponse"
Discussion Add new discussion "idAddNewDiscuss"

* = Shared with another list

Steps:

  • Add an Content Editor Web Part (CEWP) below the Announcements web part.
  • From the CEWP click Edit and Modify Shared Web Part
  • Click the Source Editor button
  • Paste the following:
<script>
  document.all("Add new announcement").innerHTML="your new text goes here"
</script> 
  • Click OK, then OK, then Exit Edit Mode

If you have more than one web part on the page with the same ID then you need to change the [0] to the number for the web part. 0=first web part, 1=second web part, etc.

document.all("Add new announcement")[0].innerHTML="your new text" 

 

If you want to get rid of the little icon just before text try this:

<script>
  var ttn_x;
  ttn_x=document.all("Add new announcement")
  // replace the text
  ttn_x.innerHTML="Click here to add team news"
  // delete or replace the image
  ttn_x.parentNode.innerHTML = ttn_x.parentNode.innerHTML.replace(/<IMG alt="" src="\/_layouts\/images\/rect\.gif">&nbsp;/,"")
</script>

If you have more than one web part on the page with the same ID then you need to change the [0] to the number for the web part. 0=first web part, 1=second web part, etc.

The image is a fragment of HTML that looks like this:

<IMG alt="" src="\/_layouts\/images\/rect\.gif">&nbsp;

The code above replaces this. JavaScript’s replace command uses regular expressions so you need to escape the “/” and “.” characters.

 

.

3 comments:

Prakash JJ said...

Yes, But if you remove (close) the content Editor Web Part the changes are lost. How to remove the Content Editor WP and still retain the settings made.

Any ideas?

Looking forward to your reply.

Thanks,

Mike Smith said...

Prakash JJ,

Don't remove it. It contains the JavaScript. Just edit its properties (Edit, Modify Shared Web Part) and in the Appearance section change the Chrome to "None".

You could also edit the page in SharePoint Designer and add the JavaScript at the bottom of the page (just before /BODY) or you could add this to the master page and it will then impact all web parts in all pages that use the master page.

Mike

Matt@HopZine said...

Hi Mike,
Thanks for the script to do this.
I got it working but now I'm losing my hair trying to change the default "There are no active announcements. To add a new announcement, click "Add new announcement" below."

This is a bit of a sticking point if I change the "Add new announcement" text!

Matt

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.