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..
- $(function() {
- $(document).on('change', '#booking_package_type', function() {
- var bol = $.inArray( $(this).val(), [ "weekend", "full_week", "midweek", "" ] );
- var pkg_type = $(this).val();
- if ( bol == -1 ) {
- $( "#booking_end_date" ).prop( "disabled", false );
- }
- else {
- $( "#booking_end_date" ).prop( "disabled", true );
- }
- console.log(pkg_type);
- $('#booking_start_date').datepicker({
- beforeShowDay: function (date) {
- console.log(pkg_type);
- if (date.getDate() == 1) {
- return [true, ''];
- }
- return [false, ''];
- }
- });
- });
- });
Now for each package selection I am getting the output as :
weekend
35weekend
midweek
35weekend
Where am I doing wrong ?