Forum Stats

  • 3,853,250 Users
  • 2,264,197 Discussions
  • 7,905,294 Comments

Discussions

Disable days in Oracle JET Datepicker

pchircop
pchircop Member Posts: 5 Blue Ribbon

I am currently using Oracle APEX v21.2,

JQuery Datepicker has been replaced by Oracle Jet Datepicker.

I want to disable all days of the week except Monday and Sunday.

I found the day-meta-data attribute in the documentation but there is no way to specify the day of the week instead of the day number in the month.

Thanks for your help

Tagged:

Answers

  • You will want to use the day-formatter attribute and pass a callback function that will determine what day of the week it is and return either disabled or not.

    Here is a function that works. It can probably be cleaned up a bit as I just quickly wrote it up. It does work in the JET Cookbook examples.

       this.formatDay = (date) => {
        let formattedDay = {disabled:true};
        let day:string
        let month:string
        if((date.month).toString().length <2) {
         month = ('0'+date.month) as string;
        }else{month = date.month)}
        if((date.date).toString().length <2) {
         day = ('0'+date.date) as string;
        }else{day = date.date)}
        let dateStr = date.fullYear+'-'+month+'-'+day+'T00:00:00' as string;
        let newDate = new Date(dateStr)
        let dayofWeek = newDate.getDay();
        console.log('dayofWeek: ' + dayofWeek);
        if(dayofWeek === 0 || dayofWeek === 1){
         formattedDay = {disabled:false};
        }
        return formattedDay
       }
    

    and the HTML is a very simple change to add the day-formatter attribute.

    <oj-input-date-time 
      id="dateTime" 
      value="{{value}}" 
      autocomplete="off" 
      day-formatter="[[formatDay]]">
    </oj-input-date-time>