hihihowru
hihihowru

Reputation: 55

ReactJS antd DatePicker enabled only every first day of each month

Using the antd/datepicker , I'm trying to enable users to choose only first day of each month whenever monthSelect is true.

The only thing I've managed to do is to enable all the dates after current and that is the case when monthSelect is false.

For now, I still have problem resolving the case where monthSelect is true. I've tried to disabled value > moment().startOf('month'), which only enables the date before first month of current month and not the following months or previous months. How can I enable datePicker for only first day of each month?

const disabledDate = (value) => {
    if (monthSelect) return value > moment().startOf('month');
    return value < moment().startOf('day');
  }
 <DatePicker 
  disabled={disabledSettingButton || disabledSaveButton}
  disabledDate={disabledDate}
  format = 'YYYY-MM-DD'
 >
 </DatePicker>

Any help would be appreciated, thanks in advance

Upvotes: 2

Views: 2089

Answers (1)

Chanandrei
Chanandrei

Reputation: 2421

Try this:

function disabledDate(value) {    
    return value.format("YYYY-MM-DD") !== moment(value).startOf('month').format("YYYY-MM-DD");
}

this will only enable the first date of each month.

Edit

Upvotes: 2

Related Questions