Category Archives: Utilities

Wrap choice-field in multiple columns: Updated version

I have preciously posted a solution for wrapping checkboxes or radio buttons in multiple rows. This one is a bit sleeker and easier to implement.

IMG

I have added a slightly modified version of “init_fields” to accommodate for lists and surveys.

Add this code to a CEWP below the form:

<style type="text/css">
.ms-RadioText label{
	white-space:nowrap;
}
</style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript">

var fields = init_fields_v3();

multichoiceVertical(['Checkboxes'],4);

function multichoiceVertical(arr,breakAfter){
	var toFind, index, counter, table;
	toFind = "td.ms-formbody";
	if($("td.ms-formbodysurvey").length>0){
		toFind = "td.ms-formbodysurvey";
	}
	$.each(arr,function(i,fin){
		if(fields[fin]!==undefined){
			index = 0;
			counter = 0;
			table = $(fields[fin]).find(toFind+' table:first');
			$(table).prepend("<tr id='vertical_"+fin+"_"+index+"'></tr>");
			$(table).find('tr:first').nextAll().each(function(){
				if(counter%breakAfter===0){
					$("#vertical_"+fin+"_"+index).after("<tr id='vertical_"+fin+"_"+(index+1)+"'></tr>");					
					index += 1;
				}				
				$(this).find('td:first').appendTo($("#vertical_"+fin+"_"+index));
				$(this).remove();
				counter += 1;
			});			
		}
	});
}

function init_fields_v3(){
	var toFind, res, myMatch, disp, fin, type
	res = {};
	toFind = "td.ms-formbody";
	if($("td.ms-formbodysurvey").length>0){
		toFind = "td.ms-formbodysurvey";
	}
	$(toFind).each(function(){
		myMatch = $(this).html().match(/FieldName="(.+)"\s+FieldInternalName="(.+)"\s+FieldType="(.+)"\s+/);	
		if(myMatch!=null){
			disp = myMatch[1];
			fin = myMatch[2];
			type = myMatch[3];
			if(type=='SPFieldNote'){
				if($(this).find('script').length>0){
					type=type+"_HTML";
				}else if($(this).find("div[id$='_TextField_inplacerte']").length>0){
					type=type+"_EHTML";
				}				
			}
			if(type=='SPFieldLookup'){
				if($(this).find('input').length>0){
					type=type+"_Input";
				}
			}
			res[fin] = this.parentNode;
			$(res[fin]).attr('FieldDispName',disp);
			$(res[fin]).attr('FieldType',type);
		}		
	});
	return res;
}

</script>

Change the script src to use a local copy of jQuery if you prefer that.

You call the function with an array of the FieldInternalNames you want top apply this solution to, and the number of columns to distribute the choices over like this:

multichoiceVertical(['Checkboxes'],4);

Alexander

Dynamic Forms for SharePoint – Now with Tabs

Change log
May 06. 2013
I have released v2.95 – you find it here
February 20, 2013 Updated to v2.70 with these changes:

  • Fixed bug where the tab setup link is missing in initial setup.
  • Added “show field description when readonly” switch under “Misc” section.
  • Added support for SP 2013.
  • Small change to the file default.css to remove form background color in SP 2013 (goes better with the SP 2013 look).
  • Added error handling when using invalid characters in the custom css setup in the heading configuration and including.
  • Added support for rules comparing date columns against other date columns in the form, or validation of empty / not empty date columns.

Read more here


January 13, 2013 Updated to v2.65 with these changes:

Fixes:

  • Validation text was shown multiple times if the rule was triggered repeatedly.
  • When saving the GUI the input values for visible or hidden tabs / headings got the previous rule value if the fields were left blank.
  • Error message in DispForm due to “customValidationMsg” being triggered.
  • Update the css file (note the text “Dynamic Forms for SharePoint v2.65” in the top) to help wrap the tabs better when not using the “Break tabs at index” option.

New features

  • It’s now possible to have a rule check other rules before triggering.

January 4, 2013 Updated to v2.61 BETA with these changes:

  • Set field value had a bug preventing choice fields from being set correctly.
  • Added MUI support for the validation message / alert.

January 1, 2013 Updated to v2.6 BETA with these new features:

  • Option to bypass all rules for selected users or groups (Misc tab).
  • Set date column value like [today], [today]-14 or [today]+14.
  • Tabs now support MUI.
  • Added support for headings (MUI).
  • Changed boolean column behavior to fix issue with hiding tabs.

You must update these files: “DynamicFormsForSharePoint.js” and “default.css”.

Regarding setting a date column to [today]
Not all reginal settings are supported. You will get an alert with instructions if your LCID is not supported.

Headings
You find the headings in the tabs section, and you add them as you do with the fields. Hover over the help icon in the GUI to learn how to set up MUI

Please note that you must update spjs-utility.js to v1.13.


04.11.2012 Updated to v2.51 with these changes:

  1. The form was hidden when no settings were found (first setup) – thus hiding the link to initiate the setup. It was still possible to use ?dfsetup=1 to initialte the setup.
  2. Whan not using TABS in SP2007, you go a javascript error:
    “The value of the property ‘ExecuteOrDelayUntilScriptLoaded’ is null or undefined, not a Function object”

01.11.2012 Updated to v2.5 with these changes:

  • Finally, you can rearrange the order of RTE fields in the tabs.
  • Initial form visibility set to hidden to prevent flashing all fields before applying rules / tabs (display:none is not used because the dialog size would be distorted).

NOTE: You must update both “DynamicFormsForSharePoint_v2.js” and “default.css”.

19.10.2012 Updated to v2.41 with these changes:

  • The action “Set field value” can now pull values from other columns in the current form (in addition to item ID) – as requested by Morten. To include a value from another field, enter the FieldInternalName like this: {Title}.
  • Added trigger “The form is saved”. This trigger will affect the action “Set field value” only.
  • Added password obfuscation as requested by Matthias.

15.10.2012 Updated to v2.4 with these changes:

  • Minimum dialog width (SP2010) set to 700px in default.css.
  • The variable “_spUserId” is changed to “_spPageContextInfo.userId” in SP2010 as some users are missing the “_spUserId” variable in their master page.
  • The edit link was previously only visible for the person who first set up the solution. It is now visible for all users. Protect the settings with the built in password functionality.
  • Added a fix to handle multiple single item lookup columns with more than 20 items in different tabs (in IE). The problem was that the options “dropdown” sometimes did not render.
  • To fix the problem when adding more than 2 rich text or enhanced rich text columns (in SP2007 only) broke the script, I have disabled the ordering of those field types completely. Put them in the top or bottom of the form (using list settings).
  • Added “Is in group trigger”.
  • Added single choice lookup columns as trigger.
  • Added show or hide tabs by rule option.

The changes are in the files “DynamicFormsForSharePoint_v2.js” and “default.css”.


18.08.2012 in v2.3:

  • Added option to show a tab only for members in selected SharePoint groups.
  • Fixed a bug in date columns when you type in the value, in combination with the “alert validation message option”.

15.08.2012 in v2.2:

  • Added option to alert the validation message.
  • Added support for “All fields tab” – to enable, add a tab with no fields.
  • Enabled solid color table background – same color as the selected tab. To disable, remove line 51-63 in the default.css file.

14.08.2012 In v2.1: Changed the “Orphan fields” handling by adding a checkbox “Show orphan fields in a separate tab” in the tabs configuration, ensured compatibility with Christophe’s Easy Tabs and changed the tab position in non-dialog forms in SP2010.


This is a follow up on Dynamic Forms for SharePoint: Production, and describes the new features – including the integration with Tabs for SharePoint forms. Please refer the previous article for an introduction to the solution.

IMG

Some of the changes:

  • Integrated with the Tabs for SharePoint forms solution. You can now rearrange the order of the fields in the tabs (not true for rich text fields).
  • Added option to hide save item button based on a rule.
  • Added option to apply a rule if the current user is not the author of the item.
  • Added option to set a field value based on a rule.
  • Added support for handling the content type selector (hide, read only, set value).
  • Added option to hide the attachments, or set them as read only (hide the “delete link”).
  • Added option to show a validation message when applying a rule.
  • Setting a field as read only now shows the field description as well.
  • Some bugfixes

The solution is still compatible with both SharePoint 2007 and 2010.

Some screenshots

Rule configuration
IMG

Tab configuration
IMG
IMG

DueDate rule
IMG
I have entered a date in the past to demonstrate the validation. Note that the save item button has disappeared.

Complete task rule
IMG
When clicking the “Completed” checkbox, the “FinalNotes” field is set as required, and the label “You must enter a brief statement in the field below.” is shown.

Tabs or Rules – or both

You can decide whether you want to use both features, or just one of them. Simply delete the last rule or tab configuration to disable that module.

Setup

Please refer this article for setup details.

There are one change to the CEWP code as you now have to refer a css-file. You also have to add an image to the same folder as the css file. This is used to add a gradient color to the tabs.

Download the files
Get jQuery here.
Get the Dynamic Forms For SharePoint files here.

Ensure you pick v2.0 or above. The image “gradient.png” must be placed in the same location as the file “default.css”.

You must also upgrade spjs-utility.js. Get spjs-utility.js v1.11 or above here.

The CEWP code:
You must change the “script src” and the “css href” to reflect your locale files.

<link type="text/css" href="https://files.spjsworks.com/files/DynamicFormsForSharePoint/v2.1/default.css" rel="stylesheet" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://files.spjsworks.com/files/spjs-utility/v1.11/spjs-utility.js"></script>
<script type="text/javascript" src="https://files.spjsworks.com/files/DynamicFormsForSharePoint/v2.1/DynamicFormsForSharePoint_v2.js"></script>
Do you use this solution?

I spend a lot of time developing these solutions. Hit the PayPal button to keep me motivated!

PayPal

Post any bugs or comments below.

Alexander

vLookup for SharePoint 2010

16.02.2013 Updated to v1.3 with these changes:

  • Added more options to process the values pulled back from the query. In addition to the previous substring, you can now have prefix and suffix and additional date formatting options. Hover over the help icon to learn more. Please note that you must reconfigure any existing “substring setup” after upgrading to v1.3.
  • Added support for hyperlink columns.
  • Added count to the “Action menu”.
  • Fixed bug with “hide field” when using a text string enclosed in curly braces in the “In URL” configuration.

25.01.2013 Updated to v1.26 Added option to split the string by a specified separator, returning a selected array index.


30.11.2012 I have updated to v1.23 to fix a compatibility issue with Office 365 for SP2013.


18.11.2012 Updated to v1.22 and added some video tutorials:

Please note that this requires v1.22 of vLookup_sp2010.js

08.11.2012 v1.2 fixes some bugs and adds some new features.
Bugs fixed:

  • Removed an extra “/NewForm.aspx” from the url generated in the “addChild” function.
  • When creating a child in a subsite or a parent site, the setting of values from the “parent item” failed due to a wrong baseUrl parameter in the URL.

Features added:

  • As suggested by “advacomp”, added an option to use a text string to set a field in the child list. See instructions on the help icon in the “In URL” section of the setup.
  • Added an option in the GUI to hide the form label in DispForm and EditForm.

16.10.2012 v1.1 fixes a bug with wrong list ID appearing when you edit the configuration from DispForm or EditForm.


I have previously posted a solution for SharePoint 2007, and by request I have rewritten the solution for SharePoint 2010. Please note that this solution will NOT work for any SharePoint version prior to SharePoint 2010.

This solution, as the previous one, supports these “methods”:

  • Show all records: Returns a list view of all the records.
  • Sum: Sums the values for all the records.
  • Average: Sums the values for all the records, and devides the sum on the number of non-empty records.

In the 2007 version, the configuration was setup in a calculated column trough the list settings > edit field.

This new solution is much easier to set up as it has a GUI:
IMG

In this solution, the configuration is stored in a dedicated list – shared by all vLookup columns in the site. This eliminates the fiddly work of hand editing the configuration.

When you first setup this solution in a site, the configuration list is created automatically. This list is not to be hand edited, and you might optionally hide it from browsers trough SharePoint Designer. You must however ensure all users have read access to this list.

You can use this solution in plain list views, grouped views and in DispForm / EditForm (see note bout field type below).

When this solution is setup in a list view, it looks like this:
IMG

DispForm and EditForm:
IMG

IMG
Adding new “Tasks” in EditForm does not refresh the form, only the “vLookup items” – thus you does not lose unsaved data in your EditForm.

How to set up the solution
  1. Download the code for the file “vLookup_sp2010.js” from here.
  2. Download the file “spjs-utility.js” from here. Ensure you get the latest version (by date of the folder).
  3. If you prefer a local copy of jQuery, get it here.
  4. Upload this files to a library in your SharePoint site collection, or to a folder in the root site – created using SharePoint Designer.
  5. Add a column to your list / library where the FieldInternalName starts with “vLookup”. This is what triggers the solution. Note that it’s the FieldInternalName and not the Display name that must match.

    You can use both a calculated column or a single line of text column as “placeholder” for the “vLookup items”. If you use a calculated column, use a formula like this:

    =""

    The contents of the field will be overwritten anyway.

    To be able to have the solution work in EditForm, you must use a single line of text column as “vLookup field”. Note that you cannot use this field to store anything as the contents will be overwritten by the vLookup solution.
  6. Add a HTML Form Web Part to the bottom of your list view, DispForm or EditForm, and add this code trough the “Source editor”:

    <script type="text/javascript" src="/test/vLookupv2/Script/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="/test/vLookupv2/Script/spjs-utility.js"></script>
    <script type="text/javascript" src="/test/vLookupv2/Script/vLookup/vLookup_sp2010.js"></script>

    IMG

    You use the exact same code for list views and for list forms.

Creating the configuration list

The first time you set up the solution, you will get this prompt:
IMG

Hit “OK” to create the list:
IMG

You will now get this prompt (provided your field is in the view):
IMG

You will now be presented with the configuration GUI:
IMG

This GUI is automatically presented while the configuration has not been created, or it contains errors that are detected by this solution. To reenter the configuration at a later time, add “vLookupSetup=1” to the URL like this:

// List view
.../Lists/MyList/AllItems.aspx?vLookupSetup=1
// DispForm
.../Lists/MyList/DispForm.aspx?ID=12&vLookupSetup=1

All the configuration option are explained by hovering over the question mark.

Creating new items in the “child list”

When you add items to the child list, and want to prefill values in your NewForm, you use the In URL section of the configuration to set the “from” and “to” fields.

You must add the same code to a HTML form web part below the form web part in NewForm as you have used in DispForm and list views. This code will pull in the values from the “parent list” and fill in the “child list”.

If you are “connecting” the two lists by a lookup column, ensure you prefill the lookup column like in the example in the top of this article.

MUI support

This solution supports MUI and you can set labels and column headers in multiple languages. Use “default” as “LCID” to have a default value and/or set up the correct LCID (matching your installed language packs) as alternate values.

Do you use this solution?
I spend a lot of time developing these free solutions. If you use it, please hit the PayPal button to send me a few bucks as motivation for releasing new solutions.

SPJS Charts for SharePoint update 18.07.2012

I have updated SPJS Charts for SharePoint to v3.3 and added a few new features.

You find the code in the original article

1. Option to have multi select in filter select

IMG
When setting up a chart filter, you now have an option “multiselect” which you can set to true to have multiple selection in the filter select. You can also specify the size of the select. See the “Instructions” link above the filter setup textarea.

2. Added formatter: ColorFormat

Description pulled from here
Assigns colors to the foreground or background of a numeric cell, depending on the cell value. This formatter is an unusual, in that it doesn’t take its options in the constructor. Instead, you should call addRange() or addGradientRange() as many times as you want, to add color ranges, before calling format(). Colors can be specified in any acceptable HTML format, for example “black”, “#000000”, or “#000”.

3. Added DataTable Roles (Experimental)

IMG
Dotted line represents uncertain numbers.

Description pulled from here
Google DataTable and DataView objects now support explicitly assigned column roles. A column role describes the purpose of the data in that column: for example, a column might hold data describing tooltip text, data point annotations, or uncertainty indicators.

Previously, there were only two roles available to a column: ‘domain’ which specifies major axis labels; and ‘data’ which specifies bar heights, pie slice widths, and so on. These roles were assigned implicitly, based on the order and type of the columns in the table. However, with the ability to explicitly assign column roles, you can now add optional columns that provide new, interesting features to a chart such as arbitrary annotation labels, hovertext, and uncertainty bars.

4. Filter multiple charts with the same filter controls

You can apply the same filter on multiple charts in a page. To do this, add the parameter “filterAdditionalCharts” to the filter setup textarea like this:

[{&quot;label&quot;:&quot;Year&quot;,&quot;urlKey&quot;:&quot;year&quot;,&quot;filterAdditionalCharts&quot;:[&quot;MyChart2&quot;],&quot;options&quot;:[{&quot;f&quot;:&quot;All&quot;,&quot;v&quot;:&quot;*&quot;},{&quot;f&quot;:&quot;2010&quot;,&quot;v&quot;:&quot;2010&quot;},{&quot;f&quot;:&quot;2011&quot;,&quot;v&quot;:&quot;2011&quot;},{&quot;f&quot;:&quot;2012&quot;,&quot;v&quot;:&quot;2012&quot;}]}]

You supply an array of additional chart container IDs to apply this filter to. If you set up multiple filters, you only have to set this parameter for the first filter select. In the additional charts, you must set up the Custom CAML to consume the filter values.

5. boolean configuration options will now be handled properly

Previously there were a problem using boolean options like “sortAscending”. This has now been fixed.

6. Alphabetically sorted field names in field select – now with FieldInternalName in parentheses

In the “Edit Chart GUI” the field names are now Alphabetically sorted. You also have the FieldInternalName in parentheses behind the display name. This might come in handy when setting up custom CAML.

7. Load the Google Visualization API release candidate

Google periodically releases a new version of the Google Visualization API. As the API does not have support for versioning, the new version is forced on everyone using this tool. To stay one step ahead, you might want to check out the release candidate before it goes live. To do this, you can set the variable “loadRC” to true in the CEWP code (as before), or you can now use a query string parameter in the URL like this:

../MyPage.aspx?loadRC=1

Alexander

Send email to distribution group stored in a SharePoint list using local email client

Change log
16.07.2014 Added support for selecting multiple groups. Please note that there may be limitations in the browser restricting the length of the mailto link.

12.11.2013 Fixed a typo in OrderBy part of the CAML.
29.06.2012 Fixed a missing “&” in line 48 – thanks to Jim.

I got a request some time ago from Brett Anderson, asking for a solution for sending a group email to users stored in a SharePoint list.

This solution can be used to harvest email addresses from a SharePoint list, and sending an email using the users local email client. It requires the email addresses to be stored in plain text.

When setup it will look like this:
IMG

Step 1

Create a list (or reuse an existing) with two fields: One for storing the email (in this example the Title field), and one for storing the distribution group name:
IMG

Add this code to a CEWP using the content link option linking to a file containing the code, or in a HTML Form web part in the sourcecode editor, somewhere in your portal:

<table cellpadding="2">
	<tr>
		<td valign="top" title="Ctrl + click to select multiple groups" style="cursor:help;">Select groups</td>
		<td valign="top" title="Use BCC to hide the addresses from the receiver" style="cursor:help;">Address option</td>
		<td valign="top"></td>
	</tr>	
	<tr>
		<td valign="top" id="groupSelectTd">
			<select id="distributionGroupSelector" multiple="multiple" size="3"></select>
		</td>
		<td valign="top">
			<input type="radio" name="cc_bcc" id="radio_to" value="to"><label for="radio_to">To</label><br>
			<input type="radio" name="cc_bcc" id="radio_cc" value="cc"><label for="radio_cc">CC</label><br>
			<input type="radio" name="cc_bcc" id="radio_bcc" value="Bcc" checked="checked"><label for="radio_bcc">BCC</label>
		</td>
		<td valign="top">
			<input type="button" onclick="doSendGroupEmail()" value="Open email client">
		</td>
	</tr>
</table>
	

<script type="text/javascript" src="/Scripts/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="/Scripts/spjs-utility/spjs-utility.js"></script>
<script type="text/javascript">

var emailgroupArgObj = {"listGuid":"SendMail",
						"listBaseUrl":L_Menu_BaseUrl,
						"groupNameField":"GroupName",
						"emailField":'Title',
						"subject":"My email subject",
						"body":"My email body"};
						
/*************************************************/						
/*********** No changes below this line **********/
/*************************************************/	
var emailObj = {};

function getEmailGroups(argObj){
	var res, qb, hb;
	qb = [];
	qb.push("<Where>");
	qb.push("<IsNotNull>");
	qb.push("<FieldRef Name='"+argObj.emailField+"' />");
	qb.push("</IsNotNull>");
	qb.push("</Where>");
	qb.push("<OrderBy><FieldRef Name='"+argObj.groupNameField+"' /></OrderBy>");
	res = spjs_QueryItems({listName:argObj.listGuid,listBaseUrl:argObj.listBaseUrl,query:qb.join(''),viewFields:['ID',argObj.emailField,argObj.groupNameField]});
	hb = [];
	$.each(res.items,function(i,item){
		if(emailObj[item[argObj.groupNameField]]===undefined){
			emailObj[item[argObj.groupNameField]] = [];
			hb.push("<option value='"+item[argObj.groupNameField]+"'>"+item[argObj.groupNameField]+"</option>");
		}
		emailObj[item[argObj.groupNameField]].push(item[argObj.emailField]);
	});
	$("#distributionGroupSelector").html(hb.join(''));
}

function doSendGroupEmail(){
	var groupIdArr = $("#distributionGroupSelector").val(), emailArr = [], link = "";
	if(groupIdArr === null){
		$("#groupSelectTd").css("background-color","#ffcccc");
		return;
	}else{
		$("#groupSelectTd").css("background-color","#ffffff");
	}
	$.each(groupIdArr,function(i,groupId){
		emailArr = $.merge(emailArr,emailObj[groupId]);
	});
	if($("#radio_to").prop('checked')){
		link += "mailto:"+emailArr.join('; ')+"&";
	}else if($("#radio_cc").prop('checked')){
		link += "mailto:?cc="+emailArr.join('; ')+"&";
	}else{
		link += "mailto:?bcc="+emailArr.join('; ')+"&";
	}
	location.href = link+"subject="+emailgroupArgObj.subject+"&body="+emailgroupArgObj.body;
}

getEmailGroups(emailgroupArgObj);
</script>
Step 2

Change the properties in the variable “emailgroupArgObj” to match your setup

  • listGuid: The list GUID or the display name of the list containing the email addresses.
  • listBaseUrl: The base url of the list containing the email addresses. If the code is in the same site, no need to change the variable L_Menu_BaseUrl.
  • groupNameField: The FieldInternalName of the field containing the group name.
  • emailField: The FieldInternalName of the field containing the email address.
  • subject: Enter a value here to have the subject field prefilled in the email client.
  • body: Enter a value here to have the body field prefilled in the email client.

Read here on how to find the list GUID and the FieldInternalNames

The script src in the code above should be changed to point to local copies of both jQuery and spjs-utility.js.
You find jQuery here, and spjs-utility.js here – ensure you use the latest version.

Ask if anything is unclear.

Alexander

Dynamic Forms for SharePoint: Production

Change log:

13.08.2012 You find an updated version here.


04.06.2012 After a few bugfixes, the current release is now v1.2.3.


02.06.2012 V1.2.1 fixes another set of bugs – here are the detail from the change log:

  • Fixed a bug that occurred when an identical rule was applied for multiple options in a single choice field (select or radio). This made the rules cancel eachother out.
  • Small update to the function “hideFields” to prevent hiding an empty required field (where the required flag was set in the list settings).
  • Another small update to the function “doReadOnly” to prevent the width of the “formlabel” to vary when toggling readonly for a field.

31.05.2012 V1.1 fixes a possible bug occurring when the Title-field is not present in the form.


Overview

This solution will let you add dependent logic to your forms:
IMG

For example you could have a Yes/No check box determines whether some fields as required or not, or the status selector in a Tasks list can toggle which fields are visible or read only when you change from “In progress” to “Completed”.

All screenshots are from SharePoint 2010, but this solution is designed for both SharePoint 2007 and SharePoint 2010. I have tested it in IE7, IE9, FireFox 12.0 and Google Chrome 19.0.1084.52, but not extensively, so please let me know if you experience problems.

I have previously posted a BETA version of this solution, but I have finally updated the Dynamic Forms for SharePoint solution to a “production release”.

Changes from the previous BETA version:
  • You can use the solution in DispForm
  • You can clone a rule, or clone the setup from NewForm to EditForm / DispForm
  • You can use a date column as trigger – though only [today] will work in this version.
  • Rich text column validation now works.
  • You can use multiple trigger values (options within same column) for one rule
  • You can check for group membership and execute rules if a user is NOT member in the group.
  • No more problems using “is not equal to”.

This article will walk trough the features and the setup of the updated version. I have added this as a separate article to keep it tidy.

Download files

Download the file “DynamicFormsForSharePoint.js” and “spjs-utility.js” from here. Please note that you will need the version dated 18.01.2012 or newer of “spjs-utility.js”. You find the files in folders with corresponding names.

You also need jQuery – download it here. You may use the latest version, but i prefer v1.6.4 as it is faster in some areas. You can not use jQuery versions below 1.6. Please note that not all of my other solutions will work with jQuery v1.7x.

Put these files in a document library or a folder created with SharePoint Designer. Ensure all users have read access to this location.

How to set up the solution

This solution is set up by referring a script from NewForm, EditForm and DispForm of the lists where you want the solution activated.

Add a CEWP to NewForm, EditForm and DispForm like this:

SharePoint 2007
Go to NewForm and EditForm and edit the URL by adding toolpaneview=2 behind the URL in this format:
…/NewForm.aspx?toolpaneview=2
…/EditForm.aspx?ID=12&toolpaneview=2
…/DispForm.aspx?ID=12&toolpaneview=2

Press Enter and you should be able to add a CEWP to the page. Put the CEWP below the form web part.

SharePoint 2010
In the list view, click “List” on the List Tools menu. Then select “Form Web Parts” and pick the form to add a CEWP to the page. Put the CEWP below the form web part.

I recommend using the Content link option in the CEWP to refer the code like the example below. The CEWP code should be put in a text file (txt) or an aspx file like in the example below. This file should be put in the same location as the file “DynamicFormsForSharePoint.js”.

CEWP setup in SharePoint 2010:
IMG

You could also put the code directly in a HTML Form web part as this web part is handled in a slightly different manner in SharePoint 2010, and therefore does not mess with the script generated HTML.

The CEWP code
&lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/Scripts/DynRequired/spjs-utility.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/Scripts/DynRequired/DynamicFormsForSharePoint.js&quot;&gt;&lt;/script&gt;

You must change the script src to all files so that they refer your local files.

These three scripts are all that goes in the CEWP – all configuration is done in a graphical user interface.

Behind the scenes

When this solution is first setup in a site, the configuration list is created automatically. This list is not to be hand edited, and it can be hidden using SharePoint Designer if you like.

When you configure the solution for a specific NewForm, EditForm or DispForm, the configuration is stored using the site-relative URL of the form as an identifier. When a user loads the form in a browser, this configuration is read from this location and the rules are applied “on the fly”.

How to configure the solution
Note on required fields
If you set a field as required in the list settings, and then hides it due to a rule when it’s still empty, the user will not be able to save the form.

When the solution is set up correctly, the only thing giving it away is the text “Dynamic Forms for SharePoint” in the bottom left corner of the form:
IMG
You click this text to enter the configuration. Note that this text number is visible only if the solution has not yet been configured for that form, or the logged in user is the one that configured the solution for this particular form in the first place.

You can however enter the edit mode manually by appending to the URL like this:
NewForm.aspx?dfsetup=1
EditForm.aspx?ID=10&dfsetup=1
DispForm.aspx?ID=10&dfsetup=1

If you set up a password protection for the configuration, you are prompted for the password when entering the edit mode:
IMG
This dialog is bypassed if a password has not been set.

You then enter the configuration:
IMG
Note that in DispForm, the only configurable setting is “These fields are hidden”. Hover the mouse over this image IMG in the GUI to get some hints on how to set up the rules for each field type.

You can use these field types as “triggers”:
Yes/No, Drop-Down Menu, Radio Buttons, Checkboxes (allow multiple selections), Single line of text, Number, Currency and Date and Time.

You can use the following operators to match their value

  • is equal to
  • is not equal to
  • is greater than
  • is less than
  • is greater than or equal to
  • is less than or equal to
  • begins with
  • contains

Not all operators can be used for all field types.

In addition to the fields, you can use *NOT member* in SharePoint group as trigger

Configuration options
Cloning rules from another form

When you have configured one form – like NewForm – you can clone the setup to another form in the same list. If you enter setup for EditForm, and you have already configured NewForm, you get this prompt:
IMG

If you press OK, you are presented with a list of already configured forms in the current list:
IMG

Multiple values in “This Value” field

You can have multiple values triggering the same rule. Add the values separated with the pipe character like this:
IMG

Yes/No fields

To configure a rule for a field of type “SPFieldBoolean” (Yes/No checkbox), you must enter a different value in NewForn / EditForm than in DispForm.
In NewForm and EditForm use true for checked and false for unchecked.
In DispForm use whatever text value representing “Yes” and “No”.

Apply rule by *NOT group membership*

You can apply a rule based on the user NOT being member in a specific group or groups (separate multiple ID’s with the pipe character):
IMG
Note that the operator dropdown is disabled.

To find the group ID, go to Site Actions > Site Settings > People and groups and click on the group name.

Look at the URL to find the group ID:
http://www.contoso.com/_layouts/people.aspx?MembershipGroupId=145

Updating from a previous version?

If you are updating from v0.9.1 or v0.9.2 I’m fairly sure all you have to do is to enter the configuration for your form, and save it again. I might be wrong, so post any bugs below.


Post any bugs or feature requests below.
Alexander

Show field description in list view column header – updated version

I have previously posted this solution that lets you add the field description to the list view column header.

By request I have updated the solution to work in a web part page with multiple lists / libraries.

Put this code in a Content Editor Web Part at the bottom of your list view or web part page:

&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var is2010 = typeof(_fV4UI)!=='undefined';

$(&quot;div[id^='WebPartWPQ']&quot;).each(function(){	
	var wpID, tCtxId, tCtx, myTooltipObj, toFind, fieldDisplayName
	wpID = $(this).attr('WebPartID').toUpperCase();	
	tCtxId = g_ViewIdToViewCounterMap[&quot;{&quot;+wpID+&quot;}&quot;];
	if(tCtxId!==undefined){
		tCtx = eval(&quot;(ctx&quot;+tCtxId+&quot;)&quot;);	
		myTooltipObj = customGetList(tCtx.listName);	
		toFind = &quot;table.ms-listviewtable th&quot;;
		if(is2010){
			toFind = &quot;div.ms-vh-div&quot;;
		}		
		$(this).find(toFind).each(function(){
			if(is2010){
				fieldDisplayName = $(this).attr('DisplayName');	
			}else{
				fieldDisplayName = $(this).find(&quot;table:first&quot;).attr('DisplayName');	
			}
			if(fieldDisplayName===undefined){
				fieldDisplayName = $(this).text();
			}
			if(myTooltipObj[fieldDisplayName]!==undefined){
				$(this).attr('title',myTooltipObj[fieldDisplayName]).find('a').attr('title',myTooltipObj[fieldDisplayName]);;
			}
		});
	}
});

function customGetList(listName){
	var xmlWrap, result;
	xmlWrap = [];
	xmlWrap.push(&quot;&lt;?xml version='1.0' encoding='utf-8'?&gt;&quot;);
	xmlWrap.push(&quot;&lt;soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'&gt;&quot;);
	xmlWrap.push(&quot;&lt;soap:Body&gt;&quot;);
	xmlWrap.push('&lt;GetList xmlns=&quot;http://schemas.microsoft.com/sharepoint/soap/&quot;&gt;');
	xmlWrap.push('&lt;listName&gt;' + listName + '&lt;/listName&gt;');
	xmlWrap.push('&lt;/GetList&gt;');
	xmlWrap.push(&quot;&lt;/soap:Body&gt;&quot;);
	xmlWrap.push(&quot;&lt;/soap:Envelope&gt;&quot;);
	result = {};
	$.ajax({
		async:false,
		type:&quot;POST&quot;,
		url:L_Menu_BaseUrl + '/_vti_bin/lists.asmx',
		contentType:&quot;text/xml; charset=utf-8&quot;,
		processData:false,
		data:xmlWrap.join(''),
		dataType:&quot;xml&quot;,
		beforeSend:function(xhr){
			xhr.setRequestHeader('SOAPAction','http://schemas.microsoft.com/sharepoint/soap/GetList');
		},
		success:function(data){
			$('Field', data).each(function(i){
				if(result[$(this).attr('DisplayName')]===undefined || result[$(this).attr('DisplayName')]===''){
					result[$(this).attr('DisplayName')] = ($(this).attr('Description')===undefined)?'':$(this).attr('Description');
				}
			});
		}
	});
	return result;
}
&lt;/script&gt;

If you like this solution, buy me a beer!

Alexander