Friday, January 17, 2014

How To Hide Save & Close For Surveys Using JavaScript

Hello Inter-webs!

Why Hide The Save & Close Button?

Before I jump into the how, lets talk about the why.  The main reason to hide the Save and Close button is due to the issues it causes for Site Admins and their users.  When a user selects Save and Close instead of selecting Finish, SharePoint treats the survey response as a working draft.  That means that the only individual who can actually access or even see the survey is the individual who created it.  Even as a site collection administrator you can only see the correct number of surveys by navigating to the /_layouts/viewlsts.aspx.  This will show you the total responses including the "drafts" but you still can't access them, so its better to hide the button all together!


How To Hide The Save and Close Button

To hide the Save and Close button you will need to:

  1. Upload the JavaScript file to your Style Library
  2. Place a Content Editor Web Part on your New & Edit forms for your survey
  3. Link the Content Editor Web Parts to the JavaScript file
  4. Hide each Content Editor Web Part
JavasScript Needed:  Save this Script into a .txt file and save it to your Assets Library

<script type=”text/javascript”>
 var x=document.getElementsByTagName(“input”);
 for (var i=0; i<x.length; i++)
 {
 if (x.item(i).type==”button” && x.item(i).value==”Save and Close”)
 {
 x.item(i).style.display=”none”;
 }
 }
 </script>


Cheers!
Dan

Thursday, January 2, 2014

SharePoint 2010: Conditionally Format Fields in a List

Hello!

This post will be covering how to use a data view web part to apply conditionally formatting to a list.  You might want to use this technique to create simple heat maps for KPIs or as a visual indicator.  An example of when this could be used is to color code expenses which are valued over $1,000.

Materials Needed:
  1. SharePoint Designer 2010
  2. A web page
  3. A List
  4. Dataview web part

Assumptions:
In this post I will be assuming that you know how to obtain SharePoint Designer 2010, create a blank wiki or web parts page, and have a list already created that you need to conditionally format.

Now that we have all of that out of the way, let us move onto the How To!

  1. Open SharePoint Designer
  2. Open Your Site
  3.  Enter Your Credentials
  4. Open the library where the page you created is stored, this is most likely in the pages or Site Pages library
  5. Right click the page that you created and select “Edit File In Advanced Mode
After opening the page in advanced mode you should be presented with Design, Split, or Code view.  We will let SharePoint Designer do the heavy lifting for this exercise, so select the Design view.

1.    Click into the web part zone that you would like to have your list displayed
2.    Select the Insert Tab on the Ribbon
3.    Select Data View
4.    Select Your List

You should now have your list on the page as a data view web part.  I have created an example list to show how we can use conditional formatting to better visualize our data.  I will be creating a visual heat map only for my Relationship field for the sake of time, but the same concept could be applied to all of my other list fields.


  1. Select your td
  2.  
  3. Select List View Tools
  4. Select Options
  5. Select Conditional Formatting
  6. Select Format Selection

  7. You will be prompted with the Condition Criteria Dialog Box
  8. Select the field you would like the condition based upon.  I will be using my Relationship field in order to create my conditions.

  9. Select the comparison and value which makes sense for your situation.  Since this list is only an example I have created extremely basic criteria.
  10. Select Set Style
  11. This dialog will provide you a list of options which could be used to conditionally format your fields.  I will be setting my Background to match the color of the entry.

You will repeat these steps for each condition that you would like to conditionally format for.  Don’t get confused by the term selection, the formation rules will be applied to all of your line items within the column.  I never had to click another td while creating my rules, the conditions will automatically cascade down.


The last step is to save your changes and to do a refresh!  Go check out your conditionally formatted data view web part!

I hope everyone was able to get this to work and fit their needs.  Please feel free to leave a comment or reach out if you have any questions J

Cheers,

Dan