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!

Richard

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

Hi Rich, I would like to apply a 6 month date restriction to an existing date property (on a form), which is editable and already has a value. I tried creating a new Validator using your code and applying it to the form field but it greys out the fields and won’t let me edit the value on the form. Can you provide any guidance?

Unfortunately Richard has since retired, however, I would be happy to assist you, should you still be having an issue. DM me and we can arrange a quick video call to try and resolve the problem.

Hi has anything been added to Netcall to allow this change or if not how would I get this to work for a date 10 days in the future?
Thanks

Hi Erin, thank you for your first contribution to the Netcall Community. I will try and get someone to help you with your query. Regards - MP