Query the event calendar (V5) with a date to determine if that date is valid or not?

I’m loading staff schedule details (into another div) based on the date selected on the mobiscroll V5 event calendar, and since I’m using the “invalid” option to disable invalid dates, the user can not select an invalid date. This is great.

However, on page load the calendar will automatically select the current date, even if it’s invalid. When this happens I don’t want to load the staff schedule details because it’s not valid. So I’m hoping there’s some way I can query the calendar object with the current date before I load the details.

Here’s my javascript

$.get("get-staffschedule.json.php?staffid=<?=$groomer?>", function(data){
  var calendar = $('#availabilitycalendar').mobiscroll5().eventcalendar({
    display: 'inline',
    invalid: [<?=$invalidstring?>],
    theme: 'material',
    themeVariant: 'light',
    responsive: {
            xsmall: {
                view: {
                    calendar: {type: 'week'}
                }
            },
            small: {
                view: {
                    calendar: {type: 'week'}
                }
            }
    },
    onSelectedDateChange: function (event, inst) {
          loadDetail(event);
    }
  }).mobiscroll5('getInst');
  calendar.setEvents(JSON.parse(data));
});

As you can see I’m calling a “loadDetail(event)” function onSelectedDateChange. This is the function that loads the staff schedule details. Since the user can’t click on an invalid date, this works fine, but I also need to call this function on page load (in that case I pass in today’s date instead of an event). That’s where I’m running into this problem.

If you can suggest any way that I can first determine whether the current date is valid or not, that would be great. Or alternatively if we can configure the calendar to automatically select the next valid date instead of the current date, that would also work.

In v5.0.3 we modified the behavior of the calendar, now if the initial date falls on an invalid date, it will jump to the next valid date.

That’s great! Thank you!