cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How do I setup a button to select tomorrow for a date field on a form

On a given form we have a date field and date picker, while 50% of the time the date we want is current date, almost all the rest of the times we want tomorrow (next business day) to be the date.

 

How can I add a button that will +1d the default date value in the date filed?

 

I've tried JS but the way I did it caused the form to reload which caused the default date to again appear in the date field... so it was both very slow and didn't actually work .

 

If I can figure out the [+1d] button to update the field I'm hopeful that I'll be able to use JS to compute weekday vs weekend and set it to be be [NextBizDay]

 

Thanks in advance for any suggestions.

 

Amir.

Labels: (2)
Tags (1)
0 Kudos
Reply
3 Replies
Highlighted
Not applicable

Re: How do I setup a button to select tomorrow for a date field on a form

Try this:

1. Set the Client ID JavaScript variable name of your date control to workingdate.

2. Add a Button control on the form and set Button type to JavaScript, and set the Client Click to getNextBusinessDate().

3. Add this to your form Custom JavaScript:

function getNextBusinessDate() {

    var $workingDate = NWF$('#' + workingdate);

    var nextDay = Date.parseLocale($workingDate.val());

    nextDay.setDate(nextDay.getDate() + 1);

    $workingDate .val(nextDay.getDate() + "/" + (nextDay.getMonth() + 1) + "/" + nextDay.getFullYear())

}

This will get the selected date from the date control (as a string) and convert it to date object, then proceed to add a day, then set the date string back to the date control. You can swap out the line 5 with your calculation logic.

Hope it helps.

0 Kudos
Reply
Community Manager Community Manager
Community Manager

Re: How do I setup a button to select tomorrow for a date field on a form

Stephen provided a great response. 

The other thought would be to use a workflow to set the date afterwards by having an option for: use next business day. This would allow the user to leave the date blank, select next business day and the workflow could then calculate the date easily and do other actions as well. 

Reply
Not applicable

Re: How do I setup a button to select tomorrow for a date field on a form

Stephen,

This was a lot of help... unfortunately I found a bug (or feature) with the setDate function.  Using setDate does not _always_ work as expected, especially when the next date is also a next month.  When I researched I found this is a known JavaScript issue and I ended up using the below code with setTime (adding a days worth of milliseconds) instead of the flawed setDate function, and due to our US date format I used the MM/DD/YYYY format. 

function getNextDay() {
var $workingDate = NWF$('#' + v_PFTD_Date);
var wDay = Date.parseLocale($workingDate.val());
var nDay = new Date();
aDay = 86400000;
nDay.setTime(wDay.getTime() + aDay);
$workingDate .val((nDay.getMonth() + 1) + "/" + nDay.getDate() + "/" + nDay.getFullYear());
}

Thank for your help, as your code lead me to this working solution.

Amir

Reply