Datetime field time formatting to current time instead of 00 and 30 minute intervals

We have an 8-page wizard form (Public forms with MS sign-in) where there are multiple datetime fields with time enabled. Regardless of restricting to 30 minute intervals in the JavaScript, the form is basing time intervals on when the form is filled out. We're trying to get HH:00 and HH:30 intervals only.

The only code formatting the dates are as such:

fd.field('SubmissionDate').value = new Date();

const dateTime30 = ['EventDate', '2ndEventDate', 'EventAnnouncementDate', 'PresaleStart', 'PresaleEnd', 'PresaleStart2', 'PresaleEnd2', 'PublicSale', 'ReservedPromoStart', 'ReservedPromoEnd', 'ReservedPromoStart2', 'ReservedPromoEnd2', 'GAPromoStart', 'GAPromoEnd', 'GAPromoStart2', 'GAPromoEnd2'];
dateTime30.forEach(timeInterval30);
function timeInterval30(item) {
fd.field(item).widgetOptions = {
interval: 30
};
}

var today = new Date();
var minDate = today.setDate(today.getDate()+7);
const blackoutDates = ['EventAnnouncementDate', 'PresaleStart', 'PresaleEnd', 'PresaleStart2', 'PresaleEnd2', 'PublicSale', 'ReservedPromoStart', 'ReservedPromoEnd', 'ReservedPromoStart2', 'ReservedPromoEnd2', 'GAPromoStart', 'GAPromoEnd', 'GAPromoStart2', 'GAPromoEnd2'];
blackoutDates.forEach(dateBlackoutFunc);
function dateBlackoutFunc(item) {
fd.field(item).widgetOptions = {
min: new Date(minDate),
};
}

First line is for the current date for the submission (only a date field). The 2nd chunk is to limit to 30 minute intervals, and the last block is to limit fields to a minimum of 7 days out from submission date.

Any ideas as to what's causing the minutes to go based on localtime of the submitter?

I've deduced the last block is going based off of time of form load, but I'm unsure how to mitigate that back to 00 and 30 min intervals.

Hello @t.sheehy,

How do users populate these Date fields? Do they fill them in manually or are they filled in programmatically?

Please export the form and share it with me, I'll test it.

Hi mniitina,

They are datetime fields the users fill in. The only script applied to that is all dates after the first one must be a minimum of 7 days out. I think that code snippet is 7 days out exactly from time of form load instead of 00:00 of that day.

How would you like me to send you the form?

@t.sheehy,

Thank you for more details, I've reproduced that on my form.

Try updating the code like so:

var today = new Date();
var minDate = new Date(today.setDate(today.getDate()+7));
const blackoutDates = ['EventAnnouncementDate', 'PresaleStart', 'PresaleEnd', 'PresaleStart2', 'PresaleEnd2', 'PublicSale', 'ReservedPromoStart', 'ReservedPromoEnd', 'ReservedPromoStart2', 'ReservedPromoEnd2', 'GAPromoStart', 'GAPromoEnd', 'GAPromoStart2', 'GAPromoEnd2'];
blackoutDates.forEach(dateBlackoutFunc);

function dateBlackoutFunc(item) {
	fd.field(item).widgetOptions = {
		min: new Date(minDate.setHours(0, 0, 0, 0))
	};
}

That worked, thank you so much for the assistance!

1 Like