Creating a new calendar event puts the start date as today's date
-
08-02-2021 - |
Question
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?
Solution
No need to use the JS code to hide the All Day Event
column. Follow below steps to achieve this:
- Go to List Settings.
- Enable Allow management of content types to Yes - Check the steps here.
- Under Content Types section, select Event.
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
- Remove
Fid
Parameter (delete everything afterField=Title
). Replace
Field
Parameter value withfAllDayEvent
(ReplaceTitle
withfAllDayEvent
).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
- Select Hidden.
- 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>