How to adjust datepicker settings from inside a on('change') function?
I have the following function:
- $("#mySelect").on('change', function() {
- var mySelectValue = $('#mySelect').val();
- var promise = getAvailableDates(mySelectValue);
- promise.done( function(data) {
- var array = data;
- $('#a_date').datepicker({
- dateFormat: "yy-mm-dd",
- beforeShowDay: function (date) {
- var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
- return [array.indexOf(string) >= 0 ]
- }
- });
-
- });
- });
My Ajax Call promise test (successful and returning data):
- function getAvailableDates(mySelectValue)
- {
- return $.ajax({
- url: '/getDoctorsAppointments/' + mySelectValue +'/',
- type: "GET",
- dataType: "json"
- });
- }
The way I want this to work:
- user selects value from #mySelect
- Ajax returns data from database based on the value selected
- 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?