Restrict a date picker to a fixed interval in future

Trying to restrict a date picker field in a customer form to only show dates from 28 days ahead of the ‘current’ date. Can see how to do it for 28 days in the past, but not 28 days later.

Hi Jo

You can use negatives, so could add -28 to get it to default to a future date?

I think however that even if you restrict the date pick to ‘only future dates’ a customer could still manually change the 28 days back to today so it might not be exactly what you are looking for?

1 Like

Hi Jo,
Darren is correct - you can just over-type the date entry field and ignore the date picker if you want. I did this check for a customer very recently, and added a fragment validator on the date fragment - doesn’t stop them picking a date outside the range but won’t let them submit the form.

let d = new Date (fragment_presenter.get_value());
let n= new Date();  // Current Date
n.setDate(n.getDate() + 28);  // Add 28 days

if (d > n)
	return {valid: false, error: "Date  must be within 28 days"};
return true;

I have edited from the original to fit your requirements - so hope I have not introduced any Typo!


1 Like

Hi Richard, I already a condition on the next button that if the date is not more than 28 days ahead it won’t show and instead displays the message ‘please chose a date more 28 days or more in the future to proceed’

Hi Jo,

I think your only option would be a custom date-picker presenter where you can apply any logic you wanted.

1 Like