How to adjust datepicker settings from inside a on('change') function?

How to adjust datepicker settings from inside a on('change') function?

I have the following function:

  1.     $("#mySelect").on('change', function() {
  2.           var mySelectValue = $('#mySelect').val();
  3.           var promise = getAvailableDates(mySelectValue);

  4.           promise.done( function(data) {

  5.             var array = data;

  6.             $('#a_date').datepicker({
  7.                dateFormat: "yy-mm-dd",
  8.                beforeShowDay: function (date) {      
  9.                    var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
  10.                    return [array.indexOf(string) >= 0 ]
  11.                }
  12.             });
  13.     
  14.           });
  15.        });


My Ajax Call promise test (successful and returning data):

  1.     function getAvailableDates(mySelectValue) 
  2.        {
  3.           return $.ajax({
  4.             url: '/getDoctorsAppointments/' + mySelectValue +'/',
  5.             type: "GET",
  6.             dataType: "json"
  7.           }); 
  8.        }

The way I want this to work: 
  1. user selects value from #mySelect 
  2. Ajax returns data from database based on the value selected 
  3. uses this data (a list of dates) to change datepicker settings. 

Everything seems to be working up until the point where I'm trying to reinitialize $('#a_date').datepicker(). But it doesn't respond to my dateFormat and beforeShowDay settings based on data returned from my Ajax call. What am I doing wrong here?