3

is there a way to change the datepicker's month on swipe? I mean any way to display next and previous month on swipe?

Here is my approach:

Jquery Mobile Swipe:

// Bind the swipeHandler callback function to the swipe event on div.box
$( "#main-page" ).on( "swipeleft", swipeLeftHandler ).on( "swiperight", swipeRightHandler );

function swipeLeftHandler( event ){
//    $( event.target ).addClass( "swipe" );
    console.log('swiped Left');
}

function swipeRightHandler( event ){
//    $( event.target ).addClass( "swipe" );
    console.log('swiped Right');
}

And Here is Jquery Mobile datePicker Code:

$(".date-input-inline").datepicker({
    onChangeMonthYear: function(year, month, inst) {

        $(".ui-datepicker").fadeOut(0);

        $(".ui-datepicker").fadeIn("normal");

    },
    dateFormat: 'yy-mm-dd',
    yearRange: currentY + ':' + currentY,
});
Asif
  • 716
  • 2
  • 15
  • 37

1 Answers1

1

use the getDate method to get the date, add a month and then set the using the setDate method to set the new date.

here's the example for the swipe right:

 var thedate=$(".date-input-inline").datepicker('getDate'); //get date from datepicker
 thedate.setMonth(thedate.getMonth()+1); //add a month 
 $(".date-input-inline").datepicker('setDate',thedate); // set the date in datepicker

swipe left would have same type of code, you just need to subtract a month.

Anam Ahmed
  • 198
  • 8