I have a weird problem with jquery UI datepicker when choosing range. Before the question, I am working on code written by lots of other people. They have included jquery Tools and UI in optimized order so all the functions work. All except jquery UI. The reason I mentioned is, I cant update the versions or switch around the order of the libraries because it breaks all the other codes :( (But I did make sure jquery, js, jquery UI is not included twice anywhere)
That said, the problem is this - I want to have two dates where the 'to' date should be later than the 'from' date. This should be easy with the following code from jquery site:
$(function() {
$( "#from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate ); //BREAKS!
}
});
$( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate ); //BREAKS!
}
});
});
The issue is the code breaks when I choose the date at the lines where I have commented as 'BREAKS!'. It is simply not detecting the 2nd datepicker inside the main datepicker function and giving me error - SCRIPT438: Object doesn't support property or method 'datepicker'
So I read the following post and decided to do stuff the following way. This works but obviously I dont have the range functionality now.
$(document).ready(function(){
$('#from').datepicker({
changeMonth: true,
changeYear: true,
numberOfMonths: 1,
showButtonPanel: true,
onSelect: function(dateText, inst) {
$('[name=wmFrom]').val(dateText); //need this part for the search filters
}
});
$('#to').datepicker({
changeMonth: true,
changeYear: true,
numberOfMonths: 1,
showButtonPanel: true,
onSelect: function(dateText, inst){
$('[name=wmTo]').val(dateText); //need this part for the search filters
}
});
});
Ok now, I am still learning js and jquery. Can any one help me implement a range functionality for this without calling/initializing datepicker inside datepicker. I know this problem probably means there is probably some issue with versions or compatibility of the libraries. But like I said I am really cant get rid of them or change much in this. Any idea/help will be very much appreciated..
MORE INFO-
This is frustrating because someone who worked before me have done things this way and any change I make break different functions. This is an internal application so cant give a link :(.
This is what I am talking about - First there is a header php which is included in the top of the problem file I am working on. This header has the link to jquery library. After including the header.php there are links to queryLoader.js, jquery.easing.1.3.js. Then There is a bunch of code which has scripts and the body html (this is where the html inputs associated with the datepicker are). Then they link /full/jquery.tools.min.js , jquery.effects.core.js, jquery.ui.core.js, jquery.ui.widget.js, jquery.ui.datepicker, query.ui.tooltip.js , jquery-ui.css. After this, there are more scripts which use functions like $.tools.validator.fn and serializeObject().
If I assume its loading jquery lib twice and change the /full/jquery.tools.min.js to /tiny/jquery.tools.min.js or /all/jquery.tools.min.js I get the following error: Object doesn't support this property or method on lines with functions such as serializeObject(). I get this when the page loads itself.
If I add the /jquery.tools.min.js after all the UI class links, I get: Object doesn't support property or method 'datepicker' at the point of datepicker initialization on the input. I get this when the page loads itself.
Who should I do :(