Hmm, you don't want the user to change this, right? You just want to show them what it's going to be? So how about this. You have a form with a date control that defaults to todays date (which you can hide if you'd like). Then you have a calculated value control that adds 2 days to the other value (which is todays date) and shows that in your "Required Date" spot, but it's not editable. Then, after submission, you have a workflow actually set your "Required Date" field and do a calculation for today + 2 days.
Hi Courtney, thanks for the response.
I actually want the date field to pre-fill to be 2 days from the current date but I want them to be able to change the date field if they want to. The current date + 2 days should be what the form populates.
Ok, then I think we're back to the Javascript option. What specifically about it wasn't working for you? Can you post your code and screenshots of the configs on the controls?
Here is the code:
NWF$(document).ready(function()
{
});
function validateStoredDate(source, arguments)
{
var varStoredDate = NWF$('#' + varStoredDateID);
var varCalculatedDate = NWF$('#' + varCalculatedDateID);
// get date from first date picker
var depart = parseDate(varStoredDate.val(),'mm/dd/yy');
// add 129 days to the retrieved date
depart.setDate(depart.getDate() + 2);
// update second date picker
varCalculatedDate.datepicker('setDate',depart);
arguments.IsValid = true;
}
function parseDate(dateString, userFormat) {
var delimiter, theFormat, theDate, month, date, year;
// Set default format if userFormat is not provided
userFormat = userFormat || 'yyyy-mm-dd';
// Find custom delimiter by excluding
// month, day and year characters
delimiter = /r^dmy]/.exec(userFormat) 0];
// Create an array with month, day and year
// so we know the format order by index
theFormat = userFormat.split(delimiter);
//Create an array of dateString.
theDate = dateString.split(delimiter);
for (var i = 0, len = theDate.length; i < len; i++){
//assigning values for date, month and year based on theFormat array.
if (/d/.test(theFormat)){
date = theDate;
}
else if (/m/.test(theFormat)){
month = parseInt(theDate, 10) - 1;
}
else if (/y/.test(theFormat)){
year = theDate;
}
}
return (new Date(year, month, date));
}
Validate step:
Stored Date for JavaScript:
Calculated Date for JavaScript:
Stored Date settings:
Result:
The first date field is the Stored Date and the screen shot was from yesterday so the date is 6/29/17 on the form. The second date is the Calculated Date which shows blank.
Thanks!
You could have a calculated value for your default current date+2. This control has a formula something like - formatDate(dateAddDays(Current Date,2),'dd/MM/yyyy') . Add a rule to this control based on the ChaneTime control i.e equals(ChangeTime,true).
Next to calculated value control have a yes/no control (tick box called ChangeTime).
On top of the calculated value control place a date/time control (MyAlternateDate - select your date) - hide this control if the Change time is not selected - equals(ChangeTime,false) You could also add a validation rule that this date control is not allowed to be less than current date+2 (dateAddDays(Current Date,-2)
Then have a form variable to with a rule something like If(equals(ChangeTime,false),MyFormDate,MyAlternateDate) .
This variable is connected to your SharePoint column. Add a formatdate to the formula of the variable if you want date only as per the default calculated value field etc.
have a look on this example how to populate datetime control based on value of other datetime control
https://community.nintex.com/message/34952?commentID=34952#comment-34952
you can add to the script date calculation that add up some days as per your requirement.
I received some help on the JavaScript and got the dates to work. I needed to add validateStoredDate(); after the ready function. The first date is +2 days and the second one is today's date.
So my full script reads as followed:
NWF$(document).ready(function()
{
validateStoredDate();
});
function validateStoredDate(source, arguments)
{
var varStoredDate = NWF$('#' + varStoredDateID);
var varCalculatedDate = NWF$('#' + varCalculatedDateID);
// get date from first date picker
var depart = parseDate(varStoredDate.val(),'mm/dd/yy');
// add 129 days to the retrieved date
depart.setDate(depart.getDate() + 2);
// update second date picker
varCalculatedDate.datepicker('setDate',depart);
arguments.IsValid = true;
}
function parseDate(dateString, userFormat) {
var delimiter, theFormat, theDate, month, date, year;
// Set default format if userFormat is not provided
userFormat = userFormat || 'yyyy-mm-dd';
// Find custom delimiter by excluding
// month, day and year characters
delimiter = /r^dmy]/.exec(userFormat) 0];
// Create an array with month, day and year
// so we know the format order by index
theFormat = userFormat.split(delimiter);
//Create an array of dateString.
theDate = dateString.split(delimiter);
for (var i = 0, len = theDate.length; i < len; i++){
//assigning values for date, month and year based on theFormat array.
if (/d/.test(theFormat)){
date = theDate;
}
else if (/m/.test(theFormat)){
month = parseInt(theDate, 10) - 1;
}
else if (/y/.test(theFormat)){
year = theDate;
}
}
return (new Date(year, month, date));
}
Thanks for the help everyone!!!