Datepicker caching the first value always

Datepicker caching the first value always

Hi,

I have a field package type: which can have either weekend or fullday. Based on the selection of this field value, I would like to make a specific date enable, and rest all I want to set as disable. And I wrote the below function inside one of my Rails app as initial script to test if I can access the value of the package_type field inside the date picker function. But I found that datepicker always caching the first value..

  
  1. $(function() {
  2. $(document).on('change', '#booking_package_type', function() {
  3. var bol = $.inArray( $(this).val(), [ "weekend", "full_week", "midweek", "" ] );
  4. var pkg_type = $(this).val();

  5. if ( bol == -1 ) {
  6. $( "#booking_end_date" ).prop( "disabled", false );
  7. }
  8. else {
  9. $( "#booking_end_date" ).prop( "disabled", true );
  10. }

  11. console.log(pkg_type);
  12. $('#booking_start_date').datepicker({
  13. beforeShowDay: function (date) {
  14. console.log(pkg_type);
  15. if (date.getDate() == 1) {
  16. return [true, ''];
  17. }
  18. return [false, ''];
  19. }
  20. });
  21. });
  22. });
  

Now for each package selection I am getting the output as :

    
weekend
35weekend
midweek
35weekend

Where am I doing wrong ?