Solved

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

Posted on 2014-02-22
4
3,228 Views
Last Modified: 2014-03-10
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

0
Comment
Question by:tonyhhisc
  • 3
4 Comments
 
LVL 14

Expert Comment

by:Pierre Cornelius
Comment Utility
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

0
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 500 total points
Comment Utility
Did you come right?
0
 

Author Closing Comment

by:tonyhhisc
Comment Utility
This worked like a charm. Thank you so much!!
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
Comment Utility
Glad to help. Good luck.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now