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,433 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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…
The viewer will learn how to dynamically set the form action using jQuery.
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…

726 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