0

I try to count the nights between departure and arrivaldate, and if the departuredate is set the arrivalate should change automatically to a day after the given departuredate.

thats my mobiscrolldatepickers

$(function(){

    $('#anreise').scroller({
        preset: 'date',
        theme: 'ios',
            dateFormat: 'dd.mm.yyyy',
            dateOrder: 'M DD ddyy',
minDate: new Date()

    });    

});

$(function(){

    $('#abreise').scroller({
        preset: 'date',
        theme: 'ios',
           dateFormat: 'dd.mm.yyyy',
            dateOrder: 'M DD ddyy'


    });    

});

thats my try of a function to calculate:

 var DatePicked = function() { 
    var departure = $("#anreise"); 
    var arrival = $("#abreise"); 
    var nights = $("#nacht"); 
    var triggeringElement = $(this); 
    var departureDate = departure.scroller("getDate"); 
    var minArrivalDate = departure.scroller("getDate"); 

    if (departureDate != null) { 
    minArrivalDate.setDate(departureDate.getDate() + 1); 
    } else { 
    minArrivalDate.setDate(minArrivalDate.getDate() + 1); 
    } 

    arrival.scroller('option', 'setDate', minArrivalDate); 


    };

and thats how i try to call the changes :

$('#anreise').scoller({ 
    onSelect: DatePicked   
    }); 

ive tryed my best to get it working but i dont know further now :)

Susan
  • 53
  • 2
  • 12

2 Answers2

1

So i figured it out:

ive added that function to my anreise-scroller:

onSelect: function() {
                                    var date1 = $('#anreise').scroller('getDate');
                                    var date2 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate() + 1);
                                    $('#abreise').scroller('option', 'minDate', date2);
                        $("#abreise").scroller("setDate",date2, true); 

                                },

Not perfekt but did it, and ive added the following code to my abreisescroller:

var currentDate = new Date();

 var nextcurrentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate() + 1);
$("#abreise").scroller("setDate",nextcurrentDate, true);

thank you

Susan
  • 53
  • 2
  • 12
0

You are using the setDate method wrong, it should be like this:

arrival.scroller('setDate', minArrivalDate, true); 
istvan.halmen
  • 3,320
  • 1
  • 23
  • 29