Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Monday, 20 April 2015

How to make attachment mandatory in SharePoint list form?

Using a list item it is not possible to make the attachment required out of the box. To make this field mandatory we will need to add JavaScript on list form.

Below is the java script which will make attachment field mandatory on list form


<script type="text/javascript" language="javascript">
function PreSaveAction() 

{
    var elm = document.getElementById("idAttachmentsTable");
    if (elm == null || elm.rows.length == 0)
    {

       document.getElementById("idAttachmentsRow").style.display='none';
       alert("Please attach Documents");
       return false ;
    }
    else
    { 
      return true ;
    }
}
</script>


Hope this helps.

Ref: https://social.technet.microsoft.com/Forums/sharepoint/en-US/c93d7611-f634-4c03-ae0d-3b5ecfe5ca6a/how-to-make-attachment-required-field


Monday, 2 January 2012

Get parameters from QueryString using JavaScript in SharePoint?

To get the querystring values, through JavaScript on a SharePoint site we can easily utilize the JSRequest object of MOSS.

It has 3 fields: QueryString, FileName, and PathName.

QueryString - is an array of key\value pairs representing the current query string parameters.
FileName - is a string containing the current name of the current page.
PathName - is the server relative path of the current page.

How to use it:

 <script language="javascript">

//First we have to call the EnsureSetup method
JSRequest.EnsureSetup();

//Get a query string parameter called ItemId. i.e. - "page.aspx?ItemId=5" will return 5
itemId = JSRequest.QueryString["ItemId"];

//Get the current page name. i.e. - "default.aspx"
itemId = JSRequest.FileName;

//Get the current path name. i.e. - "/abc/doclib/default.aspx"
itemId = JSRequest.PathName;

</script>

I hope this information will be helpful.



Monday, 31 October 2011

JavaScript and SharePoint List Form fields

Sometimes we need to hide some of the fields, set default value for fields, get the current value of fields on List new form, and edit form, display form.

We can achieve this using JavaScript.

To start with, Microsoft Team has given a good solution on this post http://blogs.msdn.com/b/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx

But there are some catches, when we use code given in above post for controls like check box, multiple line textbox.
There is a very good post on cleverworkaround which has much improved JavaScript to overcome these controls.
http://www.cleverworkarounds.com/2008/02/07/more-sharepoint-branding-customisation-using-javascript-part-1/

To return values for SharePoint field types from newform and editform, below is good post given by Alexander on his blog SharePoint JavaScript
http://sharepointjavascript.wordpress.com/2008/12/02/return-value-of-all-sharepoint-fieldtypes-with-javascript/

Hope all these information will be helpful for all of you.

Wednesday, 7 September 2011

Retrieving Rich Text Box value using JavaScript in SharePoint

Few days back I was working on one requirement to customize SharePoint list form(newform.aspx) using SharePoint designer 2007.

And I was unable to retrieve value from Rich Text box field "Analysis" in JavaScript.

I solved my issue using below JavaScript

<script type="text/javascript">

 var varAnalysis = getTagFromIdentifierAndTitle("textarea","TextField","Analysis*");
 var varAnalysisTextBoxID = RTE_GetEditorDocument(varAnalysis.id);
 var varAnalysisText = varAnalysisTextBoxID.body.innerText;

function getTagFromIdentifierAndTitle(tagName, identifier, title)
{
 var len = identifier.length;
 var tags = document.getElementsByTagName(tagName);
 for (var i=0; i < tags.length; i++)
 {
  var tempString = tags[i].id;
  if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len))
  {
   return tags[i];
  }
 }
 return null;
}
</script>

This code solved my problem.





Related Posts Plugin for WordPress, Blogger...