In this example, I am using –
- MOSS 2007
- JQuery 1.4.2 – http://jquery.com/
- SPServices (A JQuery Library) – http://spservices.codeplex.com/
First let me say, props to the SPServices developers. This is a great project and has become a necessity for my SharePoint development.
Goal – Require a unique title in a SharePoint list
This is helpful when you are using this list as a lookup value in another list or are using some other relational design.
*These steps may be slightly different depending on your configuration. This is a short and ‘to the point’ tutorial – let me know if there are some steps that would benefit from expansion.
- In SharePoint Designer, open the web site that contains the list you want to modify
- If you do not already have the JQuery and SPServices libraries installed, do this now.
- I usually create a ‘scripts’ folder in the root of the website, then create a ‘js’ folder, then upload my library files there.
- Next, find the list that you want to modify and expand it.
- Right click the “NewForm.aspx” and choose “New From Existing Page”
- This method automatically changes the list to use our new form
- In the source view of the Untitled page, find where you want to add the script tags.
- I usually add mine inside the main content placeholder.
- Paste the following text inside your document –
<!-- SPSERVICES JQUERY SCRIPT -->
<script language="javascript" type="text/javascript" src="../../scripts/js/jquery.SPServices-0.5.7.min.js"></script>
<script language="javascript" type="text/javascript" src="../../scripts/js/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$().SPServices.SPRequireUnique({
columnStaticName: "Title",
duplicateAction: 1,
ignoreCase: "true",
initMsg: "This value must be unique.",
initMsgCSSClass: "ms-vb",
errMsg: "This value is not unique.",
errMsgCSSClass: "ms-formvalidation",
completefunc: null
});
});
</script> - **Be Aware**
- You may need to correct the path of the JS libraries.
<script language="javascript" type="text/javascript" src="~YOUR-PATH/jquery.SPServices-0.5.7.min.js"></script>
- You may not need these script references if your master page references them. This all depends on your current configuration.
- You may need to correct the path of the JS libraries.
- Save the file in your list as “MyNewForm.aspx”
- Repeat from step 4, for the “EditForm.aspx” so the title uniqueness can be maintained during an edit process.
- Now access the ‘New’ button on your list; validation should stop you now from creating a duplicate title.
- Review the $().SPServices.SPRequireUnique documentation here to discover all the parameters/options.
Very creative use of jQuery. MS should include this functionality out of the box.
Waiting for more Sharepoint posts!
Thanks Greg!
Hi JEREMY BRANHAM
In my application i want to check the Unique Project Name from the list when the user enter the Project name in Project TextBox . And this check should be done for the first time of insertion. Please tell me how can i achieve and i am very new to sharepoint . It could be my pleasure if u help me
Let me know which piece you have trouble with, and I will help you.