When the date picker is open I want it to be the same width as the associated input text box. When the date picker closes, I want it to close in a single motion. But as soon I select a to and from date, no longer does the datepicker close in a single motion.
I have tried ideas such as inst.dpDiv.outerWidth(0) and partially modifying the code found here https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css. But nothing has worked and now I feel like I am going round round in circles.
I was going to include a JSFiddle but because of discrepancies between running the code in Sublime and JSFiddle I decided not to. And because the problem is only on the screen for a second (or less) I cannot take a screenshot.
I have tried hard to only include relevant code below. Does anyone have any suggestions?
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$(function(){
from = $('#arrivalDate').datepicker({
beforeShow: function (input, inst) {
setTimeout(function() {
inst.dpDiv.outerWidth($('#arrivalDate').outerWidth());
},0);
}, //End of beforeShow: function (input, inst)
onClose:function(){
if($('#arrivalDate').datepicker('getDate') != null)
{if($('#departureDate').datepicker('getDate') == null)
{jQuery('#departureDate').datepicker('show')};
}
} //End of onClose:function(){
}) // End of from = $('#arrivalDate').datepicker({
.on( "change", function(input, inst) { ///This part goes after from = $('#arrivalDate').datepicker({ xyz })
to.datepicker( "option", "minDate", $( "#arrivalDate").datepicker("getDate"))
});
to = $('#departureDate').datepicker({
beforeShow: function (input, inst) {
setTimeout(function() {
inst.dpDiv.outerWidth($('#departureDate').outerWidth());
},0);
}, //End of beforeShow: function (input, inst)
onClose:function(){
if($('#departureDate').datepicker('getDate') != null)
{if($('#arrivalDate').datepicker('getDate') == null)
{jQuery('#arrivalDate').datepicker('show')};
}
} //End of onClose:function(){
}) // End of from = $('#arrivalDate').datepicker({
.on( "change", ///This part goes after from = $('#arrivalDate').datepicker({ xyz })
function(input, inst) {
from.datepicker(
"option", "maxDate", $( "#departureDate").datepicker("getDate")
)
}
);
$('div.ui-datepicker').on('click',function(){
$(this).outerWidth($('#arrivalDate').outerWidth());
});
});
</script>
<style>
input {
width: 50%;
height: 50px
}
</style>
</head>
<body>
<div class="box">
<input id="arrivalDate" type="text" />
</div>
<div class="box">
<input id="departureDate" type="text" />
</div>
</body>
</html>
