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,265 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
ID: 39882281
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
ID: 39899798
Did you come right?
0
 

Author Closing Comment

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

Expert Comment

by:Pierre Cornelius
ID: 39919690
Glad to help. Good luck.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
window.setInterval not firing 7 31
Download a website to hdd 2 51
Clear single text form value in jquery 2 30
jQuery not working on ELSE... why? 2 25
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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)

861 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

28 Experts available now in Live!

Get 1:1 Help Now