All posts by Alexander Bautz

SPJS Charts for SharePoint: date range filter

In this article I will show you how to add a date range filter to a chart created using SPJS Charts for SharePoint v4. The code demonstrated below will query the list and get the highest and lowest date in the field specified in the query. It will then create the filter dropdowns based on the interval you select. Currently you can use “m” for month, or “y” for year.

IMG

How to set it up

To use this method for filtering a chart, you must set the variable “allowEval” to true in the CEWP code like this:

// Set this to true to allow for the use of variables in the "Filter setup textarea"
var allowEval = true;

Then you add this code to the same CEWP:

function spjs_getDateRangeFilter(list,field,interval,format){
	var q, res, start, end, split, startDate, endDate, b, d, m, y;
	// Find the start date
	q = "<Where><IsNotNull><FieldRef Name='"+field+"' /></IsNotNull></Where><OrderBy><FieldRef Name='"+field+"' Ascending='TRUE' /></OrderBy>";
	res = spjs.charts.qItems({"listName":list,"query":q,"viewFields":[field],"rowLimit":1});
	start = res.items[0][field];
	// Find the end date
	q = "<Where><IsNotNull><FieldRef Name='ID' /></IsNotNull></Where><OrderBy><FieldRef Name='"+field+"' Ascending='FALSE' /></OrderBy>";
	res = spjs.charts.qItems({"listName":list,"query":q,"viewFields":[field],"rowLimit":1});
	end = res.items[0][field];
	split = start.split(/-| |:/);
	startDate = new Date(split[0],parseInt(split[1],10)-1,split[2]);	
	split = end.split(/-| |:/);
	endDate = new Date(split[0],parseInt(split[1],10)-1,split[2]);
	b = [];
	switch(interval){
		case "m":	
			endDate.setMonth(endDate.getMonth()+1);					
		break;		
		case "y":
			endDate.setFullYear(endDate.getFullYear()+1);
		break;
		default:
			alert("The interval \""+interval+"\" is not supported. Use \"m\" for month or \"y\" for year.");
			return [{"f":"","v":""}];	
	}
	while(startDate<=endDate){
		d = startDate.getDate();
		d = d < 10 ? "0"+d : d;
		m = startDate.getMonth()+1;
		m = m < 10 ? "0"+m : m;
		y = startDate.getFullYear();
		b.push({"f":format.replace("yyyy",y).replace("MM",m).replace("dd",d),"v":String(startDate.getFullYear()+"-"+(startDate.getMonth()+1)+"-"+startDate.getDate()+" 12:00:00")});
		switch(interval){
			case "m":					
				startDate.setMonth(startDate.getMonth()+1);				
			break;		
			case "y":
				startDate.setFullYear(startDate.getFullYear()+1);
			break;		
		}
	}
	return b;
}

var myCustomFilterOptions = spjs_getDateRangeFilter("ListNameOrListGuid","FieldInternalName","m","MM/dd/yyyy");

The variable “myCustomFilterOptions” is used in the filter textarea in the chart. You can name it anything you like, preferably something that identifies the filter.

The arguments to the function “spjs_getDateRangeFilter” is as follows:
list: The DisplayName or the list GUID of the list you are querying.
field: The field internal name of the field – must be type “Date and time”.
interval: The date interval for the filter. Use “m” for month, or “y” for year.
format: The format of the visible date in the dropdown. Use any combination of dd (for day), MM (for month) and yyyy (for year).

Look her to learn how to find the list GUID and the FieldInternaleName.

This is the setup for the chart shown in the top of this article:
IMGIMG

The text in the filter textare is this:

[{"label":"Date from","urlKey":"date1","multiselect":false,"size":5,"options":myCustomFilterOptions},{"label":"Date to","urlKey":"date2","multiselect":false,"size":5,"options":myCustomFilterOptions}]

Please note the name of the variable “myCustomFilterOptions” from the CEWP code.

And the text from the Custom CAML-query textarea is this:

<Where><And><Geq><FieldRef Name='Date' /><Value Type='DateTime'>{filter:date1}</Value></Geq><Leq><FieldRef Name='Date' /><Value Type='DateTime'>{filter:date2}</Value></Leq></And></Where>

You must change the name of the filed to match the FieldInternalName of the field in your list.

Leave a comment below if you like it, or you need help setting it up.

Alexander

Display information from another list based on a lookup column connection: Updated version

Change log
November 01. 2013
v1.45: Changed the DispForm code to fix an issue with picking up the ID of the selected item. Thanks to Dmitry.

October 29. 2013
v1.44: Fixed a bug where the FieldInternalName and not the DisplayName was used as formlabel.

October 26. 2013
v1.43: Fixed a bug (data is not pulled in) in EditForm. This bug is affecting all browsers, but for IE it kicks in only when the lookup columns contains less than 20 items.

October 17. 2013
v1.42: Changed how the id of the value fields pulled back from the lookup column is generated. This to ensure unique IDs when using this feature on multiple fields. Now the ID is constructed like this:

[FieldInternalName of the Lookup column]_[FieldInternalName of the field pulled in]

Look at the bottom of the article for details.

October 17. 2013
v1.41: Added compatibility with DFFS. To achieve this, I have appended the table to the formbody of the lookup column. This to ensure the information is hidden with the field itself when changing tabs or hiding fields by rules.

This is an update of a previously posted article.

This solution lets you pull in additional information from another list based on a lookup column. It works much in the same way as the SP2010 / 2013 lookup column setting “Add a column to show each of these additional fields” found in the list settings > Change column. The difference is that this one works in NewForm and EditForm as well, where the built-in SharePoint feature only works in DispForm.
This image shows NewForm
IMG
All the highlighted fields have been pulled in based on the lookup column. Please note that these fields are not stored in the current item, but are shown when viewing the form in NewForm, DispForm or EditForm.

I have updated the code to use spjs-utility.js and thus support newer versions of jQuery and browsers other than IE. The only new feature I have added, is support for displaying the information in DispForm.

I have NOT changed the function call to ensure backwards compatibility with the older solution.

This solution is in fact only tested in SP 2007, but should work for SP2010/2013 as well. Please post any findings below.

Use this code in a CEWP below NewForm, DispForm and EditForm:

<script type="text/javascript" src="/test/English/Lists/PullInfoFromLookup/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="/test/English/Lists/PullInfoFromLookup/spjs-utility.js"></script>
<script type="text/javascript" src="/test/English/Lists/PullInfoFromLookup/PullInformationFromConnectedList.js"></script>
<script type="text/javascript">
var fields = init_fields_v2();

/* Object containing all arguments for the function
 * "arrFinAndDispName" is an array on format "FieldInternalName|Display name" from the list the lookup is pulling information from
 * "ListGuid" is the list Guid or the displayName of the list the lookup is pulling information from
 * "LookupFIN" is the FieldInternalName of the lookup column.
*/
var argumentObj = {'arrFinAndDispName':['TextField1|My text field 1',
						   'TextField2|My text field 2',
						   'TextField3|My text field 3',
						   'Responsible|Responsible',
						   'Hyperlink|Hyperlink',
						   'RichText|Rich text multi line'],
						   'ListGuid':'405EC50E-FAF7-4473-8D50-F9E725BEAA9B',
						   'LookupFIN':'MyLookupColumn'};

init_displayInfo(argumentObj);
</script>

Download the code
The code for the file “PullInformationFromConnectedList.js” can be found here, spjs-utility.js is found here, and jQuery here.

How to access the values after they have been pulled in to the table
Each of the TDs with the values have been assigned an ID like this:

MyLookupColumn_TextField1

The green part is the FieldInternalName of the lookup column, and the red part is the FieldInternalName of the field that the info is pulled from.

To get the value from this field, you use a standard jQuery selector like this

var myFieldVal = $("#MyLookupColumn_TextField1").html();
alert(myFieldVal);

Ask if anything is unclear,
Alexander

Multilingual text in a calculated column

Have you ever wanted to have the text in a calculated column translated according to the selected language in a SharePoint sites multilingual user interface?

Lets say you want to have a task list view grouped by the status of the tasks, but the statuses are in Norwegian: Ny, Under behandling and Fullført. For an English, or German speaking person these groups will not make much sense:
IMG

How about having it like this:
IMG

Or like this:
IMG

This is achieved by using a bug(?) in SharePoints handling of calculated fields that return number. We use a HTML image tag with an onload attibute to call a function.

Add a this code to the TOP of the page – ABOVE the list view:

<div id="translateCalcColumn_findAndHide" style="display:none;">This is a dummy used to remove white space above list view</div>
<script type="text/javascript" src="/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
// Remove whitespace from top of list view
$("#translateCalcColumn_findAndHide").parents("td.s4-wpcell-plain").parent().hide();
	
var spjs_translateFilterDisabled = {};	
function spjs_translate(elm){
	var $elm, oVal, a, id, o, l, td, s, v1, v2, v3;
	$elm = $(elm);
	oVal = $elm.attr("val");		
	a = $elm.attr("arr").split("#");
	id = $elm.attr("fin");
	o = {}
	$.each(a,function(i,v1){
		s = v1.split("|");
		$.each(s[1].split(","),function(j,v2){
			if(o[s[0]] === undefined){
				o[s[0]] = {};
			}
			v3 = v2.split(":");
			o[s[0]][v3[0]] = v3[1];	
		});			
	});
	if(o[oVal] !== undefined && o[oVal][g_wsaLCID] !== undefined){
		l = o[oVal][g_wsaLCID];
	}else{
		l = "<span title='Missing translation for LCID "+g_wsaLCID+"' style='color:red;cursor:no-drop;'>"+oVal+"</span>";
	}
	td = $elm.parents("td:first");
	if(spjs_translateFilterDisabled[id] === undefined && $("table.ms-listviewtable").length > 0){
		cIndex = td[0].cellIndex;
		if(!$(td).hasClass("ms-gb") && !$(td).hasClass("ms-gb2")){				
			spjs_translateFilterDisabled[id] = true;
			th = $elm.parents("table.ms-listviewtable").find("th:eq("+cIndex+") div.ms-vh-div");
			th.attr("FilterDisable","TRUE").html(th.text());
		}
	}
	if($(td).attr("class").match("ms-gb") === null){
		$(td).html(l);
	}else{
		$elm.replaceWith(l);
	}
}
</script>

And then add a calculated column to the list using this format:

="<img src='/_layouts/images/loadingcirclests16.gif' onload='spjs_translate(this)' val='"&Status&"' fin='TranslatedStatus' arr='Ny|1033:New,1031:Neue#Under behandling|1033:In Progress,1031:In Bearbeitung#Fullført|1033:Completed,1031:Fertiggestellt'>"

The red text indicates that the original value from the field “Status” is pulled in to the attribute “val” of the image. The green text is the FieldInternalName of the field, but it can be any unique value (must be unique when using multiple translatable calculated columns in one view). The blue text is the translated values in this format:
[The original value option 1]|LCID1:translated text,LCID2:translated text#[The original value option 2]|LCID1:translated text,LCID2:translated text

Please note that for this trick to work, you must set “The data type returned from this formula is: Number (1, 1.0, 100)” in the calculated column.

PS: this trick can be used in DispForm as well, but you must use this “init_fields” function to convert the HTML formatted text into proper HTML as the bug(?) only applies to list views.

function init_fields_v2(){
	var res = {};
	$("td.ms-formbody").each(function(){
	var myMatch = $(this).html().match(/FieldName="(.+)"\s+FieldInternalName="(.+)"\s+FieldType="(.+)"\s+/);	
		if(myMatch!=null){
			// Display name
			var disp = myMatch[1];
			// FieldInternalName
			var fin = myMatch[2];
			// FieldType
			var 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";
				}
			}
			// HTML Calc
			if(type==='SPFieldCalculated' && $(td).text().match(/(<([^>]+)>)/ig)!==null){
				$(td).html($(td).text());
			}		
			// Build object
			res[fin] = this.parentNode;
			$(res[fin]).attr('FieldDispName',disp);
			$(res[fin]).attr('FieldType',type);
		}		
	});
	return res;
}

Let me know in the comments below if you have trouble, or you get it working.

Alexander

SPJS Charts for SharePoint v4: Web Part Templates

To be able to easily add a chart to any page without the knowledge of JavaScript, you can create “Web Parts” in the “Web Part Gallery”. Follow these steps to be able to add a chart as you would any other web part:
IMG

First you must add two Content Editor Web Parts to a page using the “Master code”, and the “Slave code” from the setup instructions. Edit the Web Part and update these settings:
The master:
Under “Appearance”, change “Title” to “SPJS Charts for SharePoint: Master”.
Under “Advanced”, change the “Description” to “Use this Web Part to start building charts in the page. Use only one Master Web Part in each page. To load additional charts, use SPJS Charts for SharePoint: Slave.”.

The “Slave”:
Under “Appearance”, change “Title” to “SPJS Charts for SharePoint: Slave”.
Under “Advanced”, change the “Description” to “You must first add a SPJS Charts for SharePoint: Master web part to the page. Use this Web Part to load additional charts.”.

Save the changes to the web parts, and export them like this:
IMG

Save them locally, and then upload then to the “Web Part Gallery” by going to “Site settings” and selecting “Web parts” under “Galleries”. Upload them and add them under a custom Group named “SPJS”.
IMG
Now you can add the chart web parts as any other web parts to any page within the site collection.

Ask if anything is unclear,
Alexander

SPJS Charts for SharePoint v4: Generate filter values with a function

This post will describe how you can generate the filter values for a chart dynamically in SPJS Charts for SharePoint v4 using a function in the Master Web Part CEWP code.

This is something you will have to do if you want to filter a chart based on a column value that has dynamic contents and you therefore cannot use a static filter set in the chart options.

Step 1
Go to the SPJS Charts for SharePoint v4: Master Web Part, and set the variable “allowEval” to true:

<div class="spjs_chartPlaceholder_master"></div>
<script type="text/javascript">
// Load the Google Visualization API release candidate
var loadRC = false;
// Set this to true to allow for the use of variables in the "Filter setup textarea"
var allowEval = true;

var spjs_chart_license = "XXXX-XXXXXXXXXXXXXXXXXXX";
</script>

Step 2
Add the code for creating the filter to the same CEWP:

<script type="text/javascript">
function spjs_getFilterValue(list,field){
	var q = "<Where><IsNotNull><FieldRef Name='ID' /></IsNotNull></Where><OrderBy><FieldRef Name='"+field+"' /></OrderBy>";
	var res = spjs.charts.qItems({"listName":list,"query":q,"viewFields":[field]});
	var b = [];
	var fObj = {};
	$.each(res.items,function(i,item){
		if(fObj[item[field]] === undefined){
			fObj[item[field]] = 1;
			b.push({"f":""+item[field]+"","v":""+item[field]});
		}
	});
	return b;
}
var myCustomFilterOptions = spjs_getFilterValue("Poll","Answer");
</script>

This example queries the list “Poll” for the unique values in the column “Answer”. You can use any code you like to obtain these values, as long as the result is formatted like an array with this syntax:

[{"f":"Value 1","v":"Value 1"},{"f":"Value 2","v":"Value 2"}]

The “f” property is the “friendly name” that is shown in the dropdown select. This can be modified to make sense for the user. The “v” property is the value you expect to find in the database. For further instructions look at the “instructions” above the filter textarea in the “Edit chart GUI”.

Step 3
Use the variable “myCustomFilterOptions” in the filter textarea in the “Edit chart GUI”:

[{"label":"Answer","urlKey":"Answer","multiselect":false,"size":3,"options":myCustomFilterOptions}]

And use this CAML:

<Where><Eq><FieldRef Name='Answer' /><Value Type='Text'>{filter:Answer}</Value></Eq></Where>

Ask if anything is unclear.
Alexander

SPJS Charts for SharePoint v4: chartOptionOverride

This function is used in SPJS Charts for SharePoint v4 to override / intercept the chart options before the chart is drawn. You must inset this function in the Master CEWP code for it to be available when the chart is about to be drawn.

This example shows how you can color the series based on the values.

First without spjs_chartOptionOverride:
IMG

The override code:

function spjs_chartOptionOverride(chartId,data,options){
	// Color code the series based on the value
	if(chartId === "2ad99c9f-affd-4583-8146-54b03af7fa45"){
		var red = '#ff0000', green = '#00ff00', yellow = '#ffff00', value, i, j;
		options.colors = [];	
		for(i = 1; i < data.getNumberOfColumns(); i++){
			value = 0;
			for(j = 0; j < data.getNumberOfRows(); j++){
				if(data.getValue(j, i) !== null){
					value += data.getValue(j, i);
				}
			}
			options.colors.push(value > 10 ? red : (value > 5 ? yellow : green));
		}
	}
	return options;
}

Please note that this override will only affect the chart with ID “2ad99c9f-affd-4583-8146-54b03af7fa45”.

Result:
IMG

Ask if anything is unclear,
Alexander

SPJS Charts for SharePoint v4

SPJS Charts for SharePoint v5 is finally here

Change log
February 06. 2014
v4.14:
Another fix for scenarios where you have an initial filter that returns data for these columns:
“apples”, “oranges”, “bananas”You then filter the chart and get data in these columns only:
“apples”, “bananas”

You will then get an error
“Invalid column index 3. Should be an integer in the range [0-2]”

January 26. 2014
v4.11:

  • Removed the “pageId” prefix for charts stored in the configuration list. This means you now can rename web part pages containing charts without “loosing the chart”. There will be no problems with existing charts.
  • Bugfix for the following scenario: You have a chart with a filter, and you load the chart initially with a filter that returns no items. You then change the filter and select “all”. You may end up with data plotted in the wrong column / series.
  • Fixed the “Visible columns” for table charts.
  • Added option to show the data label in the column (you find it under advanced options):
    IMG
  • Minified the code.

December 7. 2013
v4.05:

  • Fixed “Consume filter from list view” where the filter value had & in it.
  • Fixed the L_Menu_BaseUrl override in SP2013 as this came out wrong in the root site.

November 7. 2013
v4.03:

  • Fixed small bug where”No items found” is repeated if you filter the chart and you get 0 items returned two or more consecutive queries.
  • Org chart now supports this format in the first column:
    {"v":"Alexander","f":"Alexander<div style='color:red;font-style:italic;'>SharePoint JavaScripts</div>"}
    

October 8. 2013
v4.01: Fixes small bug with the “Filtering…” overlay when using “filterAdditionalCharts”.

October 5. 2013
Updated the CEWP code for the Master Web Part as some users had problems loading the solution. One of the closing script tags had disappeared from the code, and this is most likely the cause. I have also moved jQuery above the JSAPI as some users fixed the problems this way.

This is v4 of SPJS Charts for SharePoint. You find the previous articles here, but please note that examples and techniques may have changed in v4.

This version, as the previous ones, lets you create charts from data stored in any lists in the site collection, and add them to any SharePoint page. The charts are created using Google Visualization API.

I have redone the script in v4, and added some improvements like support for animations, automatic refresh of the chart when the datasource is updated, and more. You find a full change log below.

This solution is still entirely client side – nothing is installed on the server.
Changelog
  • Major overhaul of the code.
  • Changed how the chart containers are named. Previously you had to name them in the CEWP, but now this is done automatically.
  • Its now much easier to add multiple charts to a page as you do not have to edit the code, just add another web part to the page.
  • Bypassed rowlimit for list views to overcome the “paging limit” when using a SharePoint view (and not Custom CAML).
  • Added timeline chart. Please note that there are some bugs in this charts tooltip in IE 10. Hopefully this will be fixed by Google in the next release.
  • Fixed preselecting multiple filter values.
  • Added support for automatically setting up filter for all single line of text columns, calculated columns, choice columns and single choice people picker columns.
  • Added support for animations when loading and filtering.
  • Added support for auto refresh of the chart when the datasource is updates.
  • The last good configuration is automatically stored. You can revert to this if there are errors in the config preventing you from loading it.
  • Added support for password protection of individual charts.
  • Added support for copying, importing and exporting chart configuration (requires licensed version).
  • Added support for setting the series color by label. Like “In progress” = green, “Deferred” = yellow and “Not started” = red. Click “Custom options” at bottom of the Options sections in Edit Chart GUI for instructions.
  • And lots of small fixes.
Deprecated features
  • The “chartOptionOverride” object has been replaced with the function “spjs_chartOptionOverride”. See details on the new function in a separate post.
  • The “prefix” for “sum”, “count” and “average” has been removed. Use numberformat: prefix in stead.
Upgrading from previous version

This solution is NOT directly compatible with previous versions (1.x, 2.x and 3.x). You must set up a new configuration list and modify all existing chart containers with the new code. When this is done, you can import your chart one-by-one from the old configuration list.

Please note that the import feature require a licensed version of SPJS Charts for SharePoint. Click here to buy a license code to unlock the import / export and copy features.

Why is it not compatible with previous versions?

The reason for not making this version backwards compatible has to do with the completely different way the configuration is stored in the configuration list, and the fact that the chart containers are no longer named in the CEWP code. The chart containers now get their unique id assigned automatically. This is done to make putting multiple charts in one page as easy as adding another web part.

Follow these steps to set up the solution
  1. Download jQuery 1.10.x from here. You can use v1.6.4 and up, but you should stay with the 1.x version as 2.x is NOT compatible with Internet Explorer 6, 7 and 8.
  2. Download spjs-charts-v4.js from here.
  3. Create a document library to hold the scripts. You must ensure all users have read access to this library. You can also create a folder using SharePoint designer.
  4. Upload the files to this library / folder.
  5. Create a text file and add this code – ensure you modify the script “src” for “jquery-1.10.2.min.js” and “spjs-charts-v4.js” to point to the location you put your files:
    <div class="spjs_chartPlaceholder_master"></div>
    <script type="text/javascript">
    // Set this to true to load the Google Visualization API release candidate
    var loadRC = false;
    // Set this to true to allow for the use of variables in the "Filter setup textarea"
    var allowEval = false;
    </script>
    <script type="text/javascript" src="/Scripts/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="/Scripts/Charts/spjs-charts-v4.js"></script>
  6. Upload the text file to the same location you put the other files.
  7. Add a CEWP to the page where you want the chart to appear, and use the “Content link” option to link to the text file with the CEWP code from step 5. You can skip step 6 and use a HTML Form Web Part and add the code in the Source editor, but I recommend using the CEWP and content link option to be able to update the code for all charts in one centralized location.
    Please note that you can NOT add the “master code” directly to a CEWP source editor. Either use the content link option in the CEWP to link to a file with the code, or use a HTML form web part. This is necessary because SharePoint messes with the code by appending the script generated contents to the CEWP when you edit the page.
  8. Reload the page and click OK on these two dialogs:
    IMG
    IMG
  9. Finished!

If you want to override the loading animation, the filtering label or the “No items found” label, add these variables to the CEWP code:

var spjs_charts_loadingOverlayLabel = "Loading chart...";
var spjs_charts_filteringLabel = "Filtering, please wait...";
var spjs_charts_noItemsFoundLabel = "No items match this filter...";
Configuring your first chart

The placeholder for the chart is indicated with a little gray downarrow where you put the CEWP. Click this image to load the configuration GUI. Here is an example chart with the configuration:
IMG
IMG

Multiple charts in the same page

In this version you basically have two different “Web parts”: The MASTER with the code referred in step 5 above, which calls the script resources, and the SLAVE which is simply any HTML DOM element with the class “spjs_chartPlaceholder”. This element can be for example a div, span or td. You can add it inline in the text, or set it up in a table structure.

The CEWP code for a SLAVE chart

<div class="spjs_chartPlaceholder"></div>
Please note that you can NOT add the “slave code” directly to a CEWP source editor. Either use the content link option in the CEWP to link to a file with the code, or use a HTML form web part. This is necessary because SharePoint messes with the code by appending the script generated contents to the CEWP when you edit the page.

You can add one Master Web Part to a page, and unlimited number of Slave Web Parts (in theory, buy your page will load slowly if you have to many charts in one page).

See separate article for instructions on how to create Web Part templates in the Web Part Gallery.

Placeholders in edit page mode

When entering edit page mode, the placeholders are highlighted like this:
IMG

Copy an existing chart

If you have the licensed version, you can copy existing charts (from v4) in two ways.
Method 1
IMG
IMG

Method 2:
Go to the chart you want to copy, select “Export configuration as text”:
IMG
IMG

Copy the text and then use “Import configuration from text” and paste it back in the new location.

Import charts from v3

If you have the licensed version, you can import existing charts (from v3) like this:
IMG
IMG

You find other articles in this series here: https://spjsblog.com/category/SPJS-Charts-for-SharePoint-v4

Do you want to buy a license code?

Click here to to learn how to obtain a license code https://spjsblog.com/license-code.

Ask if anything is unclear,
Alexander

Convert text fields to cascading dropdowns – unlimited number of levels

You find updated documentation here

Change log
August 21, 2015
Changes in v3.524

  • Fixed a bug when using single quote in the items used in the dropdown menu.

July 13, 2015
Changes in v3.523

  • Fixed issue with :multi and hide empty dropdowns not hiding the correct elements.
  • Fixed issue with :multi and autofill single option not properly selecting the items.

May 06, 2015
Changes in v3.520

  • Fixed a bug that prevented the solution from working if you did not have spjs-utility.js loaded in the page where you used the cascading dropdowns.
  • Made some changes to the debug output. The debug is now show directly in the page so there is no need to open the developer console.

April 15, 2015
Changes in v3.510

January 19, 2015
Changes in v3.30

  • Added support for autofilling values when using “Autofill subsequent dropdowns when they contain only one valid option.” in DFFS.
  • Changed the jQuery variable from $ to spjs.$ to fix a bug with SharePoints internal file “assetpicker.js” as this one kills jQuery.

September 4. 2014
Changes in v3.27
Fixed an issue where DFFS triggers on subsequent dropdowns would not trigger when the “Autofill subsequent dropdowns when they contain only one valid option” is checked (and the options are autofilled).

September 3. 2014
Changes in v3.26
Added “lookupListBaseUrl” as option in the argument to the function. This is used to lookup from a list that is not located in the same site (but in the same site collection). If you are using DFFS v4 you must update to this version.

June 10. 2014
Changes in v3.25
Skips the loading of the script if it is loaded in DispForm. This will prevent some errors when using this solution with DFFS and you are cloning settings from NewForm or EditForm.

June 7. 2014
Changes in v3.24
Added autofill of subsequent dropdowns if the field has a default value.

March 1. 2014
Changes in v3.22
Added new switches: “autoselectSingleOption” and “clearInvalidSelection”. See description below.

February 20. 2014
Changes in v3.21
Added autoselect if only one option is found.

August 29. 2013
I had forgotten a console.log in v3.1, Please download it again.
August 28. 2013
Changes in v3.1
Fixed a bug that prevents getting more then 30 items for each dropdown.

This solution lets you convert multiple single line textfields to cascading dropdowns populated by a query into another list that holds the data.

I’m reusing these two images from a previous article in this series to demonstrate the source list configuration and the target list appearance after the solution is initiated:
IMG

From v3.510 you can use multiselect in all the dropdowns.

IMG

I have previously posted two solutions in this series:
Cascading dropdowns
Cascading dropdowns in SharePoint text fields – populated by lookup in another list (version 2)

This is the third revision done mainly for compatibility with the Dynamic Forms for SharePoint solution, but it can also be used as a standalone solution. The earlier solutions had a 5-level limit, but this one in unlimited.

Used with the Dynamic Forms for SharePoint solution

Refer this solution in the CEWP where you set up the DFFS solution like this:

<link type="text/css" href="/Scripts/DFFS/default.css" rel="stylesheet">
<script type="text/javascript" src="/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="/Scripts/spjs-utility/spjs-utility.js"></script>
<script type="text/javascript" src="/Scripts/CascadingDropdowns/SPJS-Casc_min.js"></script>
<script type="text/javascript" src="/Scripts/DFFS/dffs.js"></script>

You will now find the configuration for the solution as a separate tab in the DFFS GUI:
IMG

Please note that you will not find this tab when configuring DispForm, and that this will require version 3.1 or later of the DFFS solution.
Used as a standalone solution

To use this as a standalone solution, you must do the configuration in the CEWP code like this:

<script type="text/javascript" src="/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="/Scripts/CascadingDropdowns/CascadingDropdowns.js"></script>
<script type="text/javascript">
spjs.casc.init({
	lookupList:"Cars",
	lookupListBaseUrl:L_Menu_BaseUrl,
	lookupListFields:["Make","Model"],
	thisListFields:["CarMake","CarModel"],
	dropDownDefaultvalue:"select",
	hideEmptyDropdowns:false,
	autoselectSingleOption:true,
	clearInvalidSelection:true,
	debug:false
});
</script>
Please note that the CEWP must be placed below the list view web part.
Parameters explained

lookupList: List name or GUID of the list that holds the values to populate the dropdowns.
lookupListBaseUrl: Base URL of the site where the list is located. This is NOT the URL of the list itself.
lookupListFields: The FieldInternalNames of the fields in the above list.
thisListFields: The FieldInternalNames of the fields to convert to dropdowns.
dropDownDefaultvalue: The value to display in the dropdown select when no items has been selected.
hideEmptyDropdowns: Determines whether or not to hide dropdowns with no available options.
autoselectSingleOption: If the next dropdown contains only one option it will be automatically selected.
clearInvalidSelection: If you open a list item in EditForm and the original selection no longer is a valid selection, you can decide whether to clear it or keep it.
debug: Used to troubleshoot the setup. You must have the developer console activated to read the debug information. While this is “true”, the single line of text field will show below the dropdown select.

The length of the arrays “lookupListFields” and “thisListFields” must be the same.

Using multi select

Read this article to learn how to use the multi select option for the fields.

Download code

Get the code for the file “CascadingDropdowns.js” here.

Please support the development of this solution by hitting the “beer button” in the top right corner of this page to buy me a few beers.

Have fun,
Alexander