Archive

Archive for the ‘Jquery’ Category

Extending SPFF

August 7, 2009 1 comment

Paul Grenier has created a wonderful script SPFF for manipulating Sharepoint form fields from URL. I have used javascript for field data manipulations a lot and his script makes it a breeze to implement. The fact that he has covered various forms of OOB fields is by itself worth having this as part of your toolbox.

You can download and read (extensive) documentation from codeplex http://spff.codeplex.com/

Extending SPFF:

Why?

I like URL based field manipulation, but it is not always enough and why just stick to one point of entry. If you are an user using Javascript for form manipulation you already hands on and wouldnt mind going crazy with the whole implementation script based implementation.

What:

1. There is a fix which lets you hide and set values for the fields from URL.

2. Now you can call these operation from your own Javascript code.

Download It is still uploaded as a path and waiting for approval.

E.g:

Setting values based on Drop Down values. We will use OOB task list.

In this example when a user selects “Status” as completed it will automatically set the percentage field to “100%”

image

image

Steps:

1. Follow instruction on how to load this Javascript and adding Content Editor to New/ Edit Form pagefrom Pauls codeplex page.

2. In Content Editor Source Editor Add the code below

<script language="javascript" type="text/javascript">
 _spBodyOnLoadFunctionNames.push("modifyflds");

function modifyflds()
 {
 $("select[title^=Status]").bind("change",statusChange);

}

function statusChange()
 {
 var Selected =$("select[title^=Status]").val() ;
 if(Selected=="Completed")
 $.spff({field:'% Complete',value:'100',lock:true});

}
 </script>

In the code above we are adding an “on Change” event handler on “Status” field. In the function we check if the field is completed using SPFF we set % Complete to 100%

Advertisements

(Jquery)Display Video in SharePoint Blogs from document library

March 24, 2009 4 comments

SharePoint Blogs OOB filters out all the html for embedding any kind of video in them. I use Windows live writer for my Blog post. I use one of the plug-in I think, but even though it wont embed the video within SharePoint it will show take a screenshot of  the video and link to the external site, which is fine for me.

To Display local intranet videos within blog takes bit of work, either hyperlink to media file or Content Editor web part for embedded code.

I using Jquery to accomplish this.

Instead of embedded we shall use Hyperlinks to media files and Jquery.Media plugin for turning them into inline videos.

Steps

1.Create 2 Document Libraries

  •  Media: To store all your media files.
  • Resources: To store JavaScript and other files.

2. Download Files.

3.Upload the Jquery JS and mediaplayer.swf to Resource Document library

4.  Edit Jquery Media JavaScript File . In Default Configuration section change location of mediaplayer.swf to the one you just uploaded. Save the file

clip_image002

5. Save and Upload Jquery Media to the Resources document library.

6. On Blog Home Page. Add a content Editor Web Part and Open Source Editor.

Add following script tags to it. (Change the src of javascript location to reflect the files you uploaded in steps above.)

<script type="text/javascript" src="/sharepoint/Sharepoint%20Blog/Resources/jquery-1.2.6.pack.js"></script>

<script type="text/javascript" src="/sharepoint/Sharepoint%20Blog/Resources/jquery.media.js"></script>

<script type="text/javascript" >

$("a").media();

</script>

clip_image004

7.Upload some media files to Media Library

Create a new blog post

in Body Section add a Hyperlink to a video you uploaded to Media library.

clip_image006

File Jquery Media Supports

* Supported Media Players:
*    – Flash
*    – Quicktime
*    – Real Player
*    – Silverlight
*    – Windows Media Player

For more information on Jquery Media click here  http://malsup.com/jquery/media/#overview

Note : If script doesn’t execute replace inline script with this :

<script>

function loadMedia() {

$("a").media();

}

_spBodyOnLoadFunctionNames.push("loadMedia");

</script>

If that does not work  I would try this in inline script tags

$(document).ready(function() {

$("a").media();

   });

Fix "Render Failed" Error on Groupby View using Jquery

March 10, 2009 11 comments

I recently encountered this error “&lt;!– #RENDER FAILED –&gt”.

image

I found the cause for it after searching and browsing various posts and comments about this error.

Cause:

Well it is a bug and hasnt been fixed anyway the below are the steps/combinations that cause it.

  1. Calculated Field from another list is being used as Lookup Column value in your list.
  2.  Group By the Look Up field (linked to Calculated Field in other List)
  3. Group Setting: Collapsed.

Solution: Apparently from the forums I visited turning Collapsed to Expanded in group setting fixes it and it does. Woo Hoo!.

But the problem is Collapsed setting is used to save real estate and this fix defeats that purpose.

image

Fixing with Group settings Collapsed

I had read about this Collapsing all Groups feature post at end user SharePoint  by Paul Grenier using Jquery and that seemed like a perfect candidate for this.  In This solution we shall turn Group setting to Expanded and use JavaScript to collapse on load.

Steps:
  1. Set the Group Setting to Expanded ( this will fix the error)
  2. Use the collapse all code Paul Grenier provides fire it during load.
    1. Add  Content Editor to the Page
    2. Click Edit Web Part and Add the Code below to Source Editor section of the Web Part and in Appearance Section select frame type as “None”.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type= "text/javascript">

</script>
<script type="text/javascript">
function collapseGroups() {
    $("img[src='/_layouts/images/minus.gif']:visible").parent().click();
}

_spBodyOnLoadFunctionNames.push("collapseGroups");
</script>

 

 

3. This will Collapse your Expanded Groups.

image

Done!

Issues with this method: I think in regular Group “Expand Collapse” SharePoint remembers your last collapse or group by setting. This script will ignores all that and collapses everything on Page Load

Now there are other ways to accomplish this.

  • Event handler instead of Calculated column to do the calculations and storing value in the field and use that field as look up.
  • JavaScript on Edit and New Form page, by adding  a new field and using Scripts to hide the field and populating them with calculated value (calculation done in the script). Click here to learn more