Function

$().SPServices.SPLookupAddNew

Functionality

The SPLookupAddNew function allows you to provide a link in forms for Lookup columns so that the user can add new values to the Lookup list easily. It is based on a blog post by Waldek Mastykarzv (see Credits).

How Does It Work?

The function works like this:
  1. Uses GetList for the current list to determine the details for lookupColumn
  2. Uses GetList for the Lookup column's list to determine the list's URL
  3. Uses GetFormCollection to get the URL for the NewItem form for the Lookup column's list
  4. Appends the link to the Lookup columns's formbody table cell using the promptText provided

Prerequisites

  • The form displays a Lookup column.

Syntax

$().SPServices.SPLookupAddNew({	
	lookupColumn: "",
	promptText: "Add new {0}",
	completefunc: null,
	debug: true
});
lookupColumn
The DisplayName of the Lookup column in the form

promptText
The text to display as a link to add a new value to the lookup list. If you include the {0} placeholder, it will be replaced with the value of looukupColumn. The default value is "Add new {0}".

completefunc
If specified, the completefunc will be called upon successful completion of the call to SPLookupAddNew. Potential uses for the completefunc: consistent default formatting overrides, additional lookup customizations, image manipulations, etc. You can pass your completefunc in either of these two ways:
completefunc: function() {
  ...do something...
},
or
completefunc: doSomething,                  // Where doSomething is the name of your function
debug
Setting debug: true indicates that you would like to receive messages if anything obvious is wrong with the function call, like using a column name which doesn't exist. I call this debug mode.

Example

$(document).ready(function() {
	$().SPServices.SPLookupAddNew({	
		lookupColumn: "Region Name",
		promptText: "Add new {0} "
	});
});

The prompt in this example will be 'Add new Region Name'. Other prompt examples:
  • 'Add {0}' --> 'Add Region Name'
  • 'Enter a new {0} if you want' --> 'Enter a new Region Name if you want'
  • 'Add one' --> 'Add one' (by not providing the {0} placeholder, the lookupColumn name is not displayed)
Last edited Jan 11 at 1:47 PM by sympmarc, version 16
Comments
No comments yet.

Updating...
© 2006-2010 Microsoft | About CodePlex | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2010.1.12.16187