Date Picker - help on restrictions of dates/days which can be selected

Hello,

A bit of a newbie to Javascript so forgive my ignorance here!

I'm looking for some help on the Date Picker Please. I'm creating a form where a user can request changes for an employee however for the dates I need to restrict the option on the date picker to be either a Monday, Friday or 1st of every month only.

I've got it where it will only allow certain days as below, but how/can I also allow for the 1st of every month to be selected?

fd.field('TransferDate').widgetOptions = {
disableDates: ["tuesday","wednesday","thursday","saturday","sunday"],
format: 'dd/MM/yyyy'
};

Any help would be greatly appreciated!

Thanks,
Emily

Hi @MleHig,

The simplest solution seems to be adding a validator to the field like this:

fd.rendered(function() {
    fd.field('TransferDate').addValidator({
        name: 'Confirm date',
        error: 'Date can only be a Monday, Friday, or the 1st of the month',
        validate: function(value) {
            let valueDate = new Date(value);
            if (valueDate.getDate() == 1 || valueDate.getDay() == 1 || valueDate.getDay() == 5) {
                return true;
            }
            return false;
        }
    });
});

You can learn more from this article.

Hello,
that's great! Thanks so much for your help! That's exactly what I need.

Thanks,
Emily