1

When I click the +Add button on my calendar the start/end date/time is being set to the current date instead of the date that I'm clicking on.

I believe this has to do with a script I added that converts all of my events into All Day Events. This is the script:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("ready");
function ready()
{
  // checks All Day Event
    if (!$('span[title="All Day Event"] > input').attr("checked"))
    {
    $('span[title="All Day Event"] > input').click();
    }
  //hide check-box
  $('tr:has(span[title="All Day Event"])').not('tr:has(tr)').hide();
  //$('nobr:contains("All Day Event")').closest('tr').hide();
}
</script>

How can I modify this script so that the date that I'm clicking on is the date that is pre-populated in the start/end date fields?

  • What is the default value set to your date columns (Check from List Settings-->Column settings-->Default Value)? Do you want to hide the "All Day Event" column from all the new entries (new/display/edit forms)?? – Ganesh Sanap Dec 27 '19 at 10:03
  • The default value is currently set to Today's Date. I tried setting this to None and it didn't have any affect (I guess I kind of expected that though). Yes, I want to hide the All Day Event indicator on all entries. – Joe Cambareri Dec 27 '19 at 10:18
1

No need to use the JS code to hide the All Day Event column. Follow below steps to achieve this:

  1. Go to List Settings.
  2. Enable Allow management of content types to Yes - Check the steps here.
  3. Under Content Types section, select Event.
  4. Click on Title column.

    URL will be something like: https://tenant.sharepoint.com/sites/sitename/_layouts/15/ManageContentTypeField.aspx?ctype=0x010200189C60E5DFC1BE479C71F3FE15FE12D3&List=2f1c8ffd-1abf-49c0-9b9c-090512e4ea03&Field=Title&Fid=%7Bfa564e0f%2D0c70%2D4ab9%2Db863%2D0177e6ddd247%7D

  5. Remove Fid Parameter (delete everything after Field=Title).
  6. Replace Field Parameter value with fAllDayEvent (Replace Title with fAllDayEvent).

    Now your URL should look something like: https://tenant.sharepoint.com/sites/sitename/_layouts/15/ManageContentTypeField.aspx?ctype=0x010200189C60E5DFC1BE479C71F3FE15FE12D3&List=2f1c8ffd-1abf-49c0-9b9c-090512e4ea03&Field=fAllDayEvent

  7. Select Hidden.
  8. Click OK.

This will hide the All Day Event from all list forms.

Additionally, If you don't want today's date as a default value of your columns then set it to None.

Update:

To resolve the issue mentioned in below commetns, try adding some delay/timeout to execute your script like given below (I have set it to 3 seconds. you can change it by doing some trial and error on your end):

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
    _spBodyOnLoadFunctionNames.push("ready");
    function ready() {      
        setTimeout(function(){
            // checks All Day Event
            if (!$('span[title="All Day Event"] > input').attr("checked")) {
                $('span[title="All Day Event"] > input').click();
            }
            //hide check-box
            $('tr:has(span[title="All Day Event"])').not('tr:has(tr)').hide();
            //$('nobr:contains("All Day Event")').closest('tr').hide();
        }, 3000);
    }
</script>
| improve this answer | |
  • The problem I was finding with this is that I want All Day Event to always be set to True. – Joe Cambareri Dec 27 '19 at 10:38
  • 1
    Try using the code given in update section. When you click on the "Add" button, it takes some time to set the selected date in "Start Time". So you need to run your code after SharePoint sets the selected date in "Start Time". – Ganesh Sanap Dec 27 '19 at 11:01
  • 1
    The script worked perfectly, thank you! – Joe Cambareri Dec 27 '19 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.