Can a default value be prescribed for a Cascading Dropdowns list?

Jul 6, 2011 at 11:27 PM

Marc,

Project: Cascading Dropdowns built on Content Types and Site Columns that develop a common documents taxonomy for a multi-regional organization. The top-most level begins with a Region list and cascades through Category, Subcategory, Function, Record Series lists. Each region has their own EditForm with SPCascadingDropdowns script, each script being slightly different - for example, some regions only using the top three lists. Each region is responsible for uploading and tagging their own region's documents, so they only care about choosing their Region from the top level list. Works great!

Problem: I'm trying to set the top level Parent Column to a specific value found in the Region list to save people from choosing the wrong region among other reasons. There's only a handful of regions to choose from and the organization's default desktop uses IE6-8. For example, If I'm in an Oregon EditForm, I want my relationshipListParentColumn Region to automatically enter the word "Oregon" and my relationshipListChildColumn Category to "go" off of that choice, and so forth through the other parent/child lists down the taxonomy. So, the first click on a droplist would be on Category.

Do I need to call a function like ...

var locObj = $("#FTE input[title=Region]"); // for IE, which renders an input and an image if list is 20+
locObj.attr("value","Oregon");
locObj.next("img").trigger("click");
$("input[title=Title]").focus();

... below the 

$(document).ready(function() {}

Coordinator
Jul 7, 2011 at 4:09 AM

You've got the right idea. If you set the value for the Region column prior to calling SPCascadeDropdowns with that column as the parentColumn, the cascading will happen based on that value. It's much the same as what would happen if you add the cascading to an EditForm, where the value would already have been selected.

You might also want to consider disabling the Region dropdown at the ned of the $(document).ready(function() so that the user can't inadvertantly change the value. You'll have to renable the dropdown prior to committing the changes; see my blog post about this:
http://sympmarc.com/2010/10/08/using-jquery-to-prefill-and-disable-required-column-in-a-sharepoint-form/

M.

Jul 7, 2011 at 7:04 PM

Brilliant... thanks Marc!

Here's what worked using jQuery 1.3.2 or 1.4.2 - the colon in front of "input" is essential, and the .val needs to be the number value of the Lookup column associated with the text "Oregon" instead of the text itself.

<script language="javascript" type="text/javascript" src="../../jQuery%20Libraries/jquery-1.3.2.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {

	$(':input[Title="DCRegion"]').val("5");
	$(':input[Title="DCRegion"]').attr("disabled", "disabled");

	$().SPServices.SPCascadeDropdowns({
	    relationshipList: "Category",
	    relationshipListParentColumn: "DCRegion",
	    relationshipListChildColumn: "DCORCategory",
	    parentColumn: "DCRegion",
	    childColumn: "DCORCategory",
	    debug: true
	});
	$().SPServices.SPCascadeDropdowns({
	    relationshipList: "Subcategory",
	    relationshipListParentColumn: "DCORCategory",
	    ...etc

	function PreSaveAction() {
		$((':input[Title="DCRegion"]').attr("disabled", "");
		return true;
	}
});
</script>

The dropdown does indeed work much the same as if the value was already present in the row when the Editform brings it up. The 'disabled' attribute greys out the dropdown, raising the question whether the box should even be shown to users at all. So in this case, I'll use the following script and add "style=display:none" to the DCRegion row in the EditForm table. 

<script language="javascript" type="text/javascript" src="../../jQuery%20Libraries/jquery-1.3.2.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {

	$(':input[Title="DCRegion"]').val("5");

	$().SPServices.SPCascadeDropdowns({
	    relationshipList: "Category",
	    relationshipListParentColumn: "DCRegion",
	    relationshipListChildColumn: "DCORCategory",
	    parentColumn: "DCRegion",
	    childColumn: "DCORCategory",
	    debug: true
	});
	$().SPServices.SPCascadeDropdowns({
	    relationshipList: "Subcategory",
	    relationshipListParentColumn: "DCORCategory",
	    ...etc
	
});
</script>

<tr style="display:none">
	<td width="190px" valign="top" class="ms-formlabel">
		<H3 class="ms-standardheader">
			<nobr>Region<span class="ms-formvalidation"> *</span></nobr>
		</H3>
	</td>
	<td width="400px" valign="top" class="ms-formbody">
		<SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="Edit" FieldName="DCRegion" 
				__designer:bind="{ddwrt:DataBind('u',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@DCRegion')}"/>
		<SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="DCRegion" ControlMode="Edit"/>
	</td>
</tr>

 

Coordinator
Jul 8, 2011 at 1:36 PM

I would *strongly* suggest that you move to a more recent version of jQuery. 1.3.2, and even 1.4.2, are really old, and you'll find that quite a lot of things have improved since. Also, if you're going to be using SPServices at all extensively, I don't even bother looking at those old versions anymore. It's not unlikely that you will find incompatibilities.

Glad you got it working, in any case.

M.

Jul 9, 2011 at 7:02 PM

Echo... am starting with what works. Will forge ahead testing the way to SPServices 0.62 and jQuery 1.6x.