Showing posts with label SharePoint Surveys. Show all posts
Showing posts with label SharePoint Surveys. Show all posts

2/03/2013

Add a Content Editor Web Part (CEWP) to a Survey

 

Had an interesting question… how do I add a Content Editor Web Part to a SharePoint survey. Turns out this is pretty easy, with one trick, one bug and one caveat.

  • SharePoint 2007 will need a web part trick.
  • SharePoint 2013 has a "bug" that requires you to edit the page in SharePoint Designer. The steps below include 2013 just in case they fix the bug! Be forewarned, adding a CEWP in Designer 2013 is not trivial as they left out the Design View. You have to hand edit your HTML for the web part!
  • The caveat has to do with how multipage surveys are displayed. There are only two web pages, no matter how many Page Separator columns you added; one web page for page 1 (Newform.aspx) and one web page for all other "pages" (Editform.aspx). What this means is that you cannot add a different page level (or web part) customization on "page 3" than on "page 4".
  • Trivia: Both SharePoint 2010 and 2013 surveys still use the old 2007 user interface! No ribbon!

When you respond to a multipage survey the following happens:

  1. NewForm.aspx is displayed. (this is the first "page" of your survey) When you click Next SharePoint creates a new list item in the Survey list and then loads EditPage.aspx for the rest of the questions. The URL for the first page looks like this:
      http://sharepoint/sites/Training/Lists/Survey/NewForm.aspx?IsDlg=1
        (2007 and 2013 do not add the "?IsDlg=1".)
  2. EditForm.aspx is displayed for "page 2" starting with the next question in the survey. In my example the question is named "Comments":
      http://sharepoint/sites/Training/Lists/Survey/EditForm.aspx?ID=7&FirstField=Comments&IsDlg=1
        (2007 and 2013 do not add the "?IsDlg=1".  ID is the item ID of this survey response.)
  3. EditForm.aspx is displayed for "page 3" starting with the next question in the survey. In my example the question is named "How many days?":
      http://sharepoint/sites/Training/Lists/Survey/EditForm.aspx
      ?ID=7&FirstField=How%5Fx0020%5Fmany%5Fx0020%5Fdays%5Fx003f%5F&IsDlg=1

Note that after page one the same web page (and web part) is used to display all remaining questions. They only difference is the FirstField parameter in the URL. So… an edit made to NewForm.aspx is displayed on the first page of the survey while an edit made to EditForm.aspx is displayed on all survey pages after page 1.

 

Here's the steps for SharePoint 2007, 2010 (or Office 365 2010) and 2013:

  1. Create the survey as usual
  2. Go to the survey and click "Respond to this Survey". (you will be on NewForm.aspx) If it is a multi page survey and you want to edit everything after page 1 then click Next. (You will be on EditForm.aspx)
  3. For SP 2010, right-click in a blank area in the dialog box and click Properties. Copy the URL (make sure you get it all as only two lines are displayed) Paste the URL into the browser's address bar. If you are working with 2010 then remove the "?IsDlg=1" from the URL. Press Enter to display the form.
  4. For 2007 add "&ToolPaneView=2" to the end of the URL Press Enter to display the form.
  5. For SP 2010 and 2013 click Site Actions (The "gear" for 2013) and Edit Page. (2007 is already in edit mode due to the ToolPaneView=2.)
  6. Click Add A Web Part and add your Content Editor Web Part. This is where SP 2013 fails. The panel to add a web part is displayed behind the web page. You can see it but not click it. Go to SharePoint Designer, open the site, open the survey list and edit NewForm.aspx or EditForm.aspx and add the web part there.
  7. Click the dropdown menu on the web part and click Edit Web Part. For SP 2007 click the Rich Text button. For SP 2010 click in the web part and start typing. For SP 2010 the text editor ribbon will not be displayed. You may want to create the text in another CEWP and copy and paste it into this CEWP.
  8. Click the OK in the web part's Properties panel to save your changes.
  9. Test your survey.

Tip: When you create your survey checkmark "Allow multiple responses". If you forgot to do this then go to the Survey and click Settings, Survey Settings, Title Description and Navigation.

image

 

For more survey customization options see Chapter 12 of my book SharePoint Customization for the Site Owner. 
What's in this chapter?
  • A list of survey tips, including how to create custom views
  • A better Yes/No field for surveys and lists
  • Adding a Welcome or Instructions message to the Overview page
  • Adding a Welcome, Instructions or Thank You message to the survey
  • Adding Color, Fonts and HTML to Surveys

.

1/22/2011

Book Update

 

Update! The book’s done! 

See here for the update and here for more about the book.

 

 

I made a big mistake during my presentation at the Columbus SharePoint Saturday… I mentioned that I was working on a book and that it would soon be available.  What was that about “the best-laid plans of mice and men?” As an instructor I get to teach up to forty hours a week, and each classroom hour requires three to eight hours of prep time. Over the last few months I’ve had a heavy class load and little free time for the book. (I keep letting work get in the way of hobbies and book writing!)

Several people have been pestering me about “is it out yet?” So let me tell a little about the book and maybe why it’s taking longer than expected.

 

SharePoint® 2007 and 2010 Customization for the Site Owner

by Michael T. Smith

 

There are a lot of books for SharePoint administrators and SharePoint developers, and even a few for SharePoint end users. But there is not much available for the site owner, especially on quick and easy site customization. Over the last five years I have probably trained at nearly a thousand site owners and written a lot blog articles with tips and tricks for site owners. Most of the blog articles were from site owner questions during or after class that really made me think about how to solve the problem without writing custom code. Most of these articles have been fairly short and to the point: add this web part, copy and paste this JavaScript or CSS. Each time I have written one of these blog articles I have wished I had the time to expand the article to explain more about the how and why of the solution, or to explain the logic of how I figured out how to do it so you could create more customizations like the one in the article. So I started writing the book…

The book has these goals: take what I’ve done in the blog articles as a start and then greatly expand the number of tips and tricks, explain how the tricks work, show how they can be expanded to other uses, and provide a few chapters on basic SharePoint, HTML, CSS and JavaScript skills. The first edition of the book fully supports both SharePoint 2007 and 2010 . If you have not upgraded to 2010 yet, you will one day and will want to know how to make sure these tricks still work.

 

About the other 80%

Writing a book fits the 80 / 20 rule. The first 80% of the work takes 80% of the time, and the remaining work also takes 80% of the time.  :-(   My biggest challenge in this project is knowing when to stop. It seems I can always find just one more way to do something, one more trick or one more screen capture. Where possible I’m rewriting each tip to work in SharePoint 2007 and SharePoint 2010, and as often as possible using the same code for both. I’m also adding jQuery versions of some of the examples for those who are already working with jQuery. I’m testing every trick in Internet Explorer 6 to 8 and FireFox and rewriting the JavaScript to work with all of these browsers. (really fun, let me tell ya…)

 

Book Progress

Most of the chapters are finished and are now being proof read by some nasty critics. The cover art still needs to be done. The index needs to be created. When all of that is done, the book needs to be submitted and a test copy printed to see if everything “works”, things like margins, images, cover art, etc.

 

How it will be published

I don’t see this book ever being finished. There’s just too many things I’m learning about SharePoint everyday. Books published though the traditional channels rarely get updated and I want to update the book as needed. So I am going the “self published” route using a service owned by Amazon.com. It will be first released in print format and I hope to move the book into Kindle and other electronic formats as I get time.

 

A supporting web site

The book will have a version number!  (Should I start with a beta release?)  For that and a number of other reasons the book will also have a supporting web site. There you will find all of the source code, a number of the tricks as downloadable web parts along with any new additions. So don’t get upset if you see a version 1.1 of the book after you bought 1.0. The changes will be on the site.

 

Here’s the current, but still incomplete, table of contents:

(This will change over the next few weeks…)

 

+ Chapter 1 - Read Me First
+ Chapter 2 - An HTML Primer
+ Chapter 3 - A CSS Primer
+ Chapter 4 - A JavaScript Primer
+ Chapter 5 - Hacking Tips!
+ Chapter 8 - Web Part Must Knows
+ Chapter 9 - The Content Editor Web Part
+ Chapter 10 - User Interface Customization
+ Chapter 11 - List and Library Customization
+ Chapter 12 - Surveys
+ Chapter 13 - Links Lists
+ Chapter 14 - Task Lists
+ Chapter 15 - Calendars
+ Chapter 16 - Security Tricks
+ Chapter 17 - Sound, Video, Silverlight and Flash!

 

 

Be patient!  I working as fast as I can.    :-)

12/17/2010

SharePoint: Modifying the “Respond to this Survey” Prompt

 

I had a recent request to change a survey’s “Respond to this Survey” text. Here’s two ways to do it, plus the “detective work” on how to do these kinds of changes.

 

If you just want the JavaScript solution then go ahead and scroll down to the end.

 

Solution 1: Don’t change it!

If your goal is to give the user a better way to start a survey, then just give them a direct link from Quick Launch, an Announcement or even an email. The “Respond to this Survey” button is just a link to the “Newform.aspx” for the survey and all you need to do is copy it. Here’s what the links look like:

SharePoint 2007 link:

  http://yourserver/sites/yoursite/Lists/Survey%201/NewForm.aspx?Source=http%3A%2F%2Fyourserver%2Fsites%2Fyoursite%2FLists%2FSurvey%25201%2Foverview%2Easpx

SharePoint 2010 link:

  http://yourserver/sites/yoursite/Lists/Test%20Survey/NewForm.aspx?IsDlg=1

 

Both of these give some interesting hints as to cool things you can do with these links:

  • Redirect to another page on completion: In both 2007 and 2010 you can add “?Source=” and specify a page to go to after the survey has been completed. The destination (Source) could be the survey home page, the site’s home page or a custom “Thank you” page.
     
  • Open the survey in a in a popup dialog box:  In SharePoint 2010 you can add “?IsDlg=1” to the URL to open the survey formatted for a dialog box (more info below). Without this, the survey will be displayed as a normal SharePoint page.
     
  • Note: You cannot use both “Source=” and “IsDlg” in the same URL as the user will just be redirected to a blank page.

To discover these links, just go to your survey and click “Respond to this Survey”. In SharePoint 2007 just copy the URL at the top of the browser. In SharePoint 2010, right-click inside of the dialog box and click Properties. From there you can copy the URL.

Now go to Quick Launch (Site Actions, Site Settings), a new Announcement, a new email, etc and paste the URL.

 

Adding to Quick Launch:

Here’s an example of using the link in Quick Launch. In the following example the URL will send them back to the home page after the survey has been completed:

http://yourserver/sites/yoursite/Lists/Survey%201/NewForm.aspx?Source=http://yourserver/sites/yoursite

image

As displayed in Quick Launch:

image

SharePoint 2010 and “IsDlg=1”

“IsDlg=1” alone is not enough to open a popup dialog box. “IsDlg=1” actually is an instruction to hide the master page content!  So if you want to display just the survey and only the survey, add “IsDlg=1” to the URL.

Without “IsDlg=1”

image

With “IsDlg=1”   (no Title, ribbon, Quick Launch, etc)

image

I’ll add an item to my “Blog To-Do” on show to actually display a page in a dialog box. (or you can just google/bing it!)

 

 

Solution 2: Change the “Respond to this Survey” text

Now for some detective work… Go to your survey page (overview.aspx). Right-click the page and select your browser’s “View Source” option. Search the displayed text for “Respond to this Survey”.

SharePoint 2010:  (I replaced parts of the JavaScript with “…”)

<a
id="ctl00_m_g_e2a6c7f0_8d5e_46a4_985f_8d175bfc5b24_ctl01_ctl00_toolBarTbl_RptControls_ctl00_diidIONewItem" 
accesskey="N" title="Respond to this Survey" 
onclick="javascript:NewItem2(event, ' ... ');return false;" 
href="javascript:__doPostBack('  ...  ','');">
  <img align='absmiddle' alt="Respond to this Survey" 
           src="/_layouts/images/NewItem.gif" style='border-width:0px;' />
   &#160;
  <span class="ms-splinkbutton-text">Respond to this Survey</span>
</a>

SharePoint 2007:

<a id="ctl00_m_g_bcf319ff_0b26_4f28_b8d3_70cbf4e8152a_ctl00_ctl00_toolBarTbl_RptControls_ctl00_diidIONewItem" 
accesskey="N" title="Respond to this Survey" 
onclick="javascript:NewItem(' ... ');return false;" 
href="javascript:__doPostBack(' ... ','');">
<img align='absmiddle' alt="Respond to this Survey" 
         src="/_layouts/images/NewItem.gif" style='border-width:0px;'>
  &nbsp;Respond to this Survey
</a>

 

Just enough difference to be a nuisance! But note that in both we have three copies of “Respond to this Survey” to change. One in the A tag, one in the IMG tag and one at the end of the A tag (and for 2010, inside a SPAN tag).

Now for some detective work:

So how do we find the one A tag out of all of the HTML on this page? I never depend on IDs with lots of strange characters (they tend to change from page to page) so that leaves out the normal best solution:  document.getElementById(“ctl00 ….. “). We could just loop through the A tags looking for one with a title of “Respond to this Survey”. And that will work fine, but as a best practice we may want this to work regardless of the language settings used to create the site.

So I see two other useful possibilities, find A tags with an ID that ends with “IONewItem” or find IMG tags that have ‘src="/_layouts/images/NewItem.gif"’. I’m going to use the first of these two.

 

So first let’s find the A tag: 

var atags = document.getElementsByTagName("A");
for (var i=0;i<atags.length;i++)
{
  if (atags[i].id.indexOf("IONewItem")>0)
  {
    // make text changes here...
  }
}

Now let’s change the text:

The first change is easy. As we already have found the “A” tag (atags[i]) all we need to is change the title property:

var newsurveytext = "Click here for the survey!";
atags[i].title = newsurveytext;

The second change is not too hard… The A tag contains two or three child nodes and the first one is the image. All we need to do to it is change the ALT attribute:

atags[i].childNodes[0].alt = newsurveytext;

We need to be careful with the next part as we want it to work in both 2007 and 2010. As 2007 has two nodes (IMG and the text) and 2010 has three nodes (the IMG, the “&#160;” text and the SPAN) we just need to check the count of nodes to make the correct edit for each version:

if (atags[i].childNodes.length == 2)
{
  // must be 2007  ("\u00A0" is to replace the &nbsp;)
  atags[i].childNodes[1].nodeValue = "\u00A0" + newsurveytext;
}
else
{
  // must be 2010 (and we hope the next version!)
  atags[i].childNodes[2].innerText = newsurveytext;
}

 

So here’s the final solution:

<script>

var atags = document.getElementsByTagName("A");
for (var i=0;i<atags.length;i++)
{
  if (atags[i].id.indexOf("IONewItem")>0)
  {
    var newsurveytext = "Click here for the survey!";
    atags[i].title = newsurveytext;
    atags[i].childNodes[0].alt = newsurveytext;
    if (atags[i].childNodes.length == 2)
    {
      // must be 2007  ("\u00A0" is to replace the &nbsp;)
      atags[i].childNodes[1].nodeValue = "\u00A0" + newsurveytext;
    }
    else
    {
      // must be 2010 (and we hope the next version!)
      atags[i].childNodes[2].innerText = newsurveytext;
    }
    break;  // no need to check the other A tags
  }
}

</script>

 

To add the JavaScript to SharePoint 2007

  1. Go to the survey page (overview.aspx)
  2. Click Site Actions and Edit Page
  3. Click Add a Web Part and select the Content Editor Web Part
  4. Move the Content Editor Web Part below the existing survey web part (important!)
  5. Edit the Content Editor Web Part and click the Source Editor button
  6. Copy and Paste the JavaScript above, changing the “newsurveytext” to your text
  7. Save and test

Or… edit the page (overview.aspx) in SharePoint Designer and add the JavaScript just be for the closing tag for the placeholder named “PlaceHolderMain”.

To add the JavaScript to SharePoint 2010

  1. Open Notepad, Copy and paste the JavaScript above, changing the “newsurveytext” to your text
  2. Save the file to a local drive
  3. Upload the file to a SharePoint library (while Shared Document will do, you may want a add a library just for these kinds of files)
  4. Go to the library where you just uploaded the file and copy the URL to the file (right-click the file and click Properties to find the URL)
  5. Go to the survey page (overview.aspx)
  6. Click Site Actions and Edit Page
  7. Click Add a Web Part and select the Content Editor Web Part
  8. Move the Content Editor Web Part below the existing survey web part (important!)
  9. Edit the Content Editor Web Part and paste the URL to the JavaScript file into the Content Link box
  10. Save and test

Or… edit the page (overview.aspx) in SharePoint Designer and add the JavaScript just be for the closing tag for the placeholder named “PlaceHolderMain”.

 

.

7/22/2010

SharePoint: Add Instructions and Color to Surveys

 

Only tested in SharePoint 2007 so far…

 

Survey Instructions

Surveys often need instructions or opening text. Here is a trick that converts a “Single line of text” question into just a page of text. There is one side effect; your “instructions question” will show up in the results as a query that everyone answered as “HIDDEN”. (But you could change the word if you like.)

 

image

Steps:

  1. For each "Instructional Text" needed in the survey add a question to the survey of type “Single line of text”, add your text as the question, and set a default value of "HIDDEN"
     
  2. If you want the instructions on their own page, then add a Page Separator after the instructions item
     
  3. Go to your survey and click “Respond to this Survey” to display the Newform.aspx page
     
  4. Edit the URL to allow access to the web parts:
      append this to the end of the URL for the NewForm.aspx URL:  
                &ToolPaneView=2 
    and press Enter  

    http://yourserver/sites/yoursite/Lists/SurveyTest/NewForm.aspx?Source=.......overview.aspx&ToolPaneView=2
  5. Click “Add a Web Part” and add a Content Editor Web Part
     
  6. Move the Content Editor Web Part below the list web part
     
  7. Edit the web part, click the Source Editor button and add the JavaScript from below
     
  8. Save your changes and go test the survey!
<script>
 // hide the input textbox for the "description" text
 var x = document.getElementsByTagName("INPUT");
 var i=0;
 for (i=0; i<x.length; i++)
 { 
  if (x[i].value=="HIDDEN")
  {
    x[i].style.display="none";
  }
 } 
</script>

Note: If you have a multipage form (you added page separators or branching logic) then you will need to add a web part with the same code as above in the EditForm.aspx page. To get to this page just respond to the survey and click Next. Then to add the web part add &ToolPaneView=2 to the end of the URL.

 

 

Add color to your surveys!

 

Just follow the steps above, but use the following JavaScript instead. Then manually embed your HTML in the text of the question: "This is a survey about <b><i>Important Stuff</i></b>. Please take your time."

<script>
 // Fix tags to allow HTML
 var t = document.getElementsByTagName('table');
 for (var i=0; i<t.length; i++)
 {
   if (t[i].className=='ms-formtable')
   {
     var td = t[i].getElementsByTagName('td');
     for (var j=0;j<td.length;j++)
     {
       if (td[j].innerHTML.indexOf('&lt;') > -1)
       {
         td[j].innerHTML = td[j].innerHTML.replace(/&lt;/g,'<').replace(/&gt;/g,'>'); 
       }
     }
   }
 }
</script>

 

 

Or add instructions and color!

Use both JavaScript routines together:

<script>
 // hide the input textbox for the "description" text
 var x = document.getElementsByTagName("INPUT");
 var i=0;
 for (i=0; i<x.length; i++)
 { 
  if (x[i].value=="HIDDEN")
  {
    x[i].style.display="none";
  }
 } 

 // Fix tags to allow HTML
 var t = document.getElementsByTagName('table');
 for (var i=0; i<t.length; i++)
 {
   if (t[i].className=='ms-formtable')
   {
     var td = t[i].getElementsByTagName('td');
     for (var j=0;j<td.length;j++)
     {
       if (td[j].innerHTML.indexOf('&lt;') > -1)
       {
         td[j].innerHTML = td[j].innerHTML.replace(/&lt;/g,'<').replace(/&gt;/g,'>'); 
       }
     }
   }
 }
</script>

 

.

3/11/2010

SharePoint 2010: What’s New in Surveys

 

Note: the following is for the November 2009 Beta 2. In this release surveys do not have a ribbon in all screens and retain most of the look and feel of 2007.

 

What’s new?

Almost nothing! The exercise of comparing the two versions almost seems a waste of time due to the few changes, but I have had a number of questions from folks hoping for many new features in surveys. Remember this is the beta and the final release may still have changes.

 

No changes:

  • Settings, Title, description and navigation
  • Audience targeting settings
  • Delete this survey
  • Save as template
  • Manage permissions (new ribbon, but core features are unchanged)
  • RSS settings

New, but common to most SharePoint 2010 lists and libraries - while useful in other lists these often do not add value to surveys

  • Validation Settings
  • Rating Settings
  • Metadata navigation settings
  • Per-location view settings
  • Generate file plan report
  • Form settings

Changed, but common to most SharePoint lists and libraries:

  • Information management policy settings
  • Advanced - Some new wording, and the addition of two new but common items: “Offline Client Availability” and “Dialogs”.

Survey Questions:

  • All the old question types are still there
  • “Business Data” has been replaced with “External Data”
  • New! Managed Metadata

Survey Questions – details…

  • “Enforce unique values” – Interesting new option! This is really useful for lists where each item must have a unique value (I.e. each item is for one State and two items for the state is not allowed). This will have limited value for surveys.
  • “Column Validation”  (only available for Single line of text, Choice, Number, Currency, Date & Time) – used to validate the entered data against a rule (formula) – Example:  “[Amount] > 25” – the formula can reference the current field or any other field in the same item (row / survey response)
  • Currency now has more currency types…
  • Lookup
    • can now display multiple columns from the lookup list – BUT they are not displayed in the survey or the results (this is really a feature for columns in lists)
    • can enforce relational integrity (not of much value to a survey)
  • Yes/No is just as bad as before! (just a bare checkbox that defaults to Yes)
  • Person or Group now allows multiple selection (2007 only lets you select a single user)

 

.

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.