Link to home
Start Free TrialLog in
Avatar of tonyhhisc
tonyhhisc

asked on

Jquery UI Datepicker w/Multidatepicker plugin, After Selecting a Date go back to same month as selection

I am using the Jquery UI Datepicker and it's working great except one last little fix needed.

The calendar pops up, and allows you to select multiple dates until you click "Done" or click outside of the datepicker popup.

What I want, is after the user clicks a date, say the calendar starts at January but the user selects a date in April. After selecting the date in april the calendar jumps back to show the month of January, where it started. I want it to show the month April so user can continue selecting in the month of April instead of having to click back to April each time they select another date.

I almost had it working by using this option in my jQuery.datepicker call:

onSelect: function(dateText, inst) { $( ".datepicker2" ).datepicker( "setDate" , dateText )

It works, by bringing the user back to the same month as just selected, However, it trumps the other dates that were previously selected, so then it only allows you to select one date instead of multiples.

It seems I just need something other than the "setDate" method but my excellent google searching skills have turned up nothing after many tries.

Thanks for any help you can give!!


My current Code looks like this:
<script>
$(function() {
  var date = new Date();
  $( ".datepicker").multiDatesPicker({
    minDate: 0, showButtonPanel: true, changeMonth: true, changeYear: true, onSelect: function(dateText, inst) { $( ".datepicker" ).datepicker( "setDate" , dateText ) }
  });
});
</script>

Open in new window

Avatar of Pierre Cornelius
Pierre Cornelius
Flag of South Africa image

Are you using the multidatespicker plugin on sourceforge?

Set the defaultDate in the settings param when user selects a date.
onSelect: function(dateText, inst) { inst.settings.defaultDate = dateText; }

See below for working example:
<!DOCTYPE html>
<html>
<head>
	<title>DatePicker</title>
	<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />	
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
	<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
	<!--<script src="jquery-ui-1.10.1.custom.js"></script> -->
	<script src="http://multidatespickr.sourceforge.net/jquery-ui.multidatespicker.js"></script> 
</head>
<body>
	<form action="#">
	<p>Date: <input type="text" id="datepicker" class="datepicker"/></p>
	</form>
	<script>
				
		$(function() {
		  $( ".datepicker").multiDatesPicker({
			minDate: 0, showButtonPanel: true, changeMonth: true, changeYear: true			
				, onSelect: function(dateText, inst) { inst.settings.defaultDate = dateText; }
				
		  });
		});
		
	</script>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Pierre Cornelius
Pierre Cornelius
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tonyhhisc
tonyhhisc

ASKER

This worked like a charm. Thank you so much!!
Glad to help. Good luck.