Tuesday, June 9, 2015

Set "All day Events" as default in SharePoint Calendar


We have "All day Event" option in SharePoint calendar list. Let me explain about how to set "All day event" by default. First Add a content editor webpart in Newform.aspx of calendar list. Then, Paste the below script in content editor

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>

<script>
$(document).ready(function(){

if (!$('span[title="All Day Event"] > input').attr("checked"))
{
  $('span[title="All Day Event"] > input').click();
}

});
</script>

Save Content Editor and Click Stop Editing in the ribbon. Now we can see the "All Day Event" set for an event by default. 

10 comments:

  1. Holy cow this was the only version I found on the internet that worked, must be something to do with the $(document).ready part.
    Thanks a lot!

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. There is a bug though: when adding the event by clicking on a cell in the calendar, the Start Time defaults to Today's date instead of the date of the cell I clicked. Must be something to do with $(document).ready conflicting with sharepoint stuff. I'm looking into using _spBodyOnLoadFunctionNames instead.

      Delete
    3. Nice Zen. Please let me know the steps for $(document).ready conflict issue.

      Delete
    4. The issue still remained with _spBodyOnLoadFunctionNames, On a hunch I discovered that this seems to be time related. I got around the issue by instituting a delay in the script to give SharePoint time to write the requested date.

      jQuery('nobr:contains("All Day Event")').closest('tr').hide();
      setTimeout(hideAllDay, 1000);
      function hideAllDay() {
      if (!jQuery('span[title="All Day Event"] > input').attr("checked"))
      {
      jQuery('span[title="All Day Event"] > input').click();
      }

      Delete
  2. unfortunately its not work for me , i'm using share point online and need to set my events as all day event

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Using jquery-2.2.4.min.js

      You might want to disable the checkbox or hide the row too.

      if ($('[name$=AllDayEventField]').prop('checked') == false) {
      $('[name$=AllDayEventField]').click();
      }

      Delete
  3. This comment has been removed by the author.

    ReplyDelete