Posts

Showing posts with the label JavaScript

Set SharePoint List Form Web Part field values using JavaScript when Creating New Item

How to set values of form fields generated by the SharePoint List Form Web Part when adding a new item to the list using JavaScript. Using a custom metadata field in a SharePoint list to set categorisation & filter criteria that is later used by List and Data View Web Parts to arrange & filter content for specific audiences.  Depending on the audience that a user is in, I wish to set alternate default values for specific fields rendered by the List Form Web Part. In most cases, a custom multiple choice field in the list will be set to a value which corresponds to the current user’s audience, but will sometimes need to be manually adjusted.  To improve the experience for end users, the appropriate checkbox option from the multiple choice field that corresponds to the current user’s audience will be selected when the form loads, and the default value for the field un-checked if required. The custom field is used in multiple content types across the primary site col...

Useful Tip: Add a link to Create a New Document From a Content Type Template

I found a blog post by Andy Burns that explains how to find and use the javascript from the 'New' button on a Document Library with managed content types to add a link to any page which will open a new document from the template. As the "add new document" link on the summary toolbar of a List or Data View Web Part links to the Upload page of the document library, i used the javascript from the new button instead to create a link that opens a new blank document from the content type template associated with the document library.  This meant that the default save location for the document was set to the document library. Andy's post explains how to incorporate the javascript behind the 'New' button into a link on a different page. The issue that I was attempting to resolve is that I wanted to use the link in client applications outisde of SharePoint.  this meant that I couldn't use javascript, as the function called was not available to the applica...

Split List View web part labels (javascript)

The following is a javascript function created to split long questions / column titles on a SharePoint survey or list when editing ( EditForm.aspx / DispForm.aspx ). I had a survey with questions containing hundreds of characters. When the EditForm.aspx / DispForm.aspx pages render the survey for completion, the questions are wrapped in < nobr > tags, which results in the page's width being much larger than the browser, regardless of resolution. The function takes all < nobr > elements and replaces those which match required criteria. Each question / column in the survey starts with a number, which is followed by the question ( "1. ..." "2. ..." etc.). The function runs through a series of tests to determine the currrent question. If the beginning of the line matches the required question number, contents of the element is replaced to include a break ( < br >) tag to split the line. Possible improvements: Split the question string after a s...