Updating the Animation for Datepicker Closure

While using the date picker, I want it to match the width of the input text box. When closing the date picker, I prefer a smooth and single motion. However, after selecting a from and to date, the datepicker no longer closes smoothly.

I have attempted solutions like inst.dpDiv.outerWidth(0) and modifying code from , but none have resolved the issue, leaving me stuck in a loop.

I considered sharing a JSFiddle, but discrepancies between Sublime and JSFiddle made it difficult. The problem vanishes too quickly for a screenshot as well.

I've tried to include only relevant code below. Any suggestions?

Update - Thanks to Ghassen Louhaichi for the edit; you can observe the stuttering in the snippet below.

$(function() {
    from = $('#arrivalDate').datepicker({
        beforeShow: function(input, inst) {
            setTimeout(function() {
                inst.dpDiv.outerWidth($('#arrivalDate').outerWidth());
            }, 0);
        },
        onClose: function() {
            if ($('#arrivalDate').datepicker('getDate') != null) {
                if ($('#departureDate').datepicker('getDate') == null) {
                    jQuery('#departureDate').datepicker('show');
                }
            }
        }
    })
    .on('change', function(input, inst) {
        to.datepicker('option', 'minDate', $('#arrivalDate').datepicker('getDate'));
    });

    to = $('#departureDate').datepicker({
        beforeShow: function(input, inst) {
            setTimeout(function() {
                inst.dpDiv.outerWidth($('#departureDate').outerWidth());
            }, 0);
        },
        onClose: function() {
            if ($('#departureDate').datepicker('getDate') != null) {
                if ($('#arrivalDate').datepicker('getDate') == null) {
                    jQuery('#arrivalDate').datepicker('show');
                }
            }
        }
    })
    .on('change', function(input, inst) {
        from.datepicker('option', 'maxDate', $('#departureDate').datepicker('getDate'));
    });
    
    $('div.ui-datepicker').on('click', function() {
        $(this).outerWidth($('#arrivalDate').outerWidth());
    });
});
input {
  width: 50%;
  height: 50px;
}
<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="https://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>

<div class="box"><input id="arrivalDate" type="text" /></div>
<div class="box"><input id="departureDate" type="text" /></div>

Answer №1

When working with the jquery-ui.js file, a modification was required in the code:

// inst.dpDiv.removeClass( "ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4" ).width( "" );

The change that needed to be made was:

inst.dpDiv.removeClass( "ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4" );

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Mouseover function not triggering until clicked on in Google Chrome

I'm attempting to execute a function when the cursor hovers over a list item as shown below: <div id="vue-app"> <ul> <li v-for="item in items" @mouseover="removeItem(item)">{{item}}</li> </ul> </div> ...

Revamp the style of the date field in a Material UI dialog

I'm currently working on a React project where I am using Material-UI's date picker component to display date items. However, I find that the default style does not meet my requirements. I would like to use a selector for displaying dates in the ...

Issue with angular directive scope not binding correctly

Good day I'm relatively new to Angular and directives, but I'm facing an issue with the scope (in my specific case). I have defined the directive as follows: angular.module('ToolBarMod', ['ngAria']) .controller('ToolBar ...

Searching for a way to detect when a user clicks the back button on their Android or iPhone device using JavaScript or

In the process of building a Single Page Application (HTML5) utilizing the following plugins: - Sammy.js - Knockout.js - Require.js - Jquery.js This app is designed for Android, iPhone, and Windows mobile devices. Many scenarios revolve around cli ...

Finding the specific ajax object that has been returned

Here is the code snippet I am currently working with: $.ajax({ type: 'POST', url: rAction, data: rData, success: function(msg){ if(msg.indexOf('ERROR:')>1){ } if(msg.indexOf('ERROR:&ap ...

Tips for retrieving the ID value of the <li> element using JavaScript and AJAX

Here is a snippet of code I've been using to send the value of an <option>: function getXhr() { var xhr = null; if(window.XMLHttpRequest) // Firefox et autres xhr = new XMLHttpRequest(); else if(window.ActiveXObject){ // I ...

What is the best way to use jQuery to display the character represented by an ASCII code &###?

Struggling with printing text? I am trying to append some content to an array, but it's showing special characters like &aacute; instead of the actual accented letters. Any suggestions on how to fix this issue? This is for a select tag, so I&apos ...

Swap out the <a> tag for an <input type="button"> element that includes a "download" property

I have been working on a simple canvas-to-image exporter. You can find it here. Currently, it only works with the following code: <a id="download" download="CanvasDemo.png">Download as image</a> However, I would like to use something like th ...

React's setState is not reflecting the changes made to the reduced array

I am currently working on a custom component that consists of two select lists with buttons to move options from the available list to the selected list. The issue I am facing is that even though the elements are successfully added to the target list, they ...

Retrieve the data of elements that have been clicked using jQuery

I am struggling with a particular issue and would appreciate some assistance. Recently, I've been working on developing buttons that, when clicked, add data to a form for submission. An example of the code structure is as follows: <div> < ...

Concurrent AJAX requests within the Vaadin JavaScript extension

Currently, I am in the process of developing a straightforward Vaadin Extension using javascript where I subclass AbstractJavaScriptExtension. The main objective is to trigger a method call on the server side that will involve tasks such as loading data an ...

Extracting Json data with Jquery

My JSON data format is as follows - I've been struggling to find a way to retrieve the photo reference value. Can anyone help me with this? { "debug_info" : [], "html_attributions" : [ "Listings by \u003ca href=\"http://www.yellowpages. ...

Tips for including a JSON file within the utils directory of a Node.js project

I have a JavaScript file located in the utils folder of my Node.js project. This JS file is responsible for retrieving data from a database. However, at the moment, I only have mock data stored in a local JSON file. Now, I need to figure out how to load th ...

Maintain button activation status even upon reloading the page (utilizing PHP and HTML)

Is it possible to maintain the active state of a button even after reloading the page without using custom CSS, only Bootstrap? I am using PHP and the buttons function as a switch for ON or OFF in an if condition. HTML <div style="margin-top: 20px ...

Tips for invoking a Laravel Model function with a parameter in a Vue.js template

I'm facing an issue with displaying stock quantities for products in a Vue.js template. I have a product table and stock table where data about product sale and purchase are stored. I need to calculate the stock of each product based on purchase and s ...

In Firefox, the CSS height and width values are displayed as X pixels, whereas in Internet Explorer, they are automatically set to 'auto'

When it comes to measuring div box dimensions, jQuery can be a handy tool. Here is an example code snippet: $(document).ready(function(){ var h = $("#testbox").css("height"); }); Interestingly, the same code can give different results in different brow ...

Is it HTML True or False in the editor?

For the HTML template I'm working on, I want to implement a feature where users can toggle tags on and off easily. My idea is to make it as simple as setting a value to "true" or "false." Is there a way to achieve this within a single HTML file? ...

What is the best way to incorporate line breaks into a reportlab PDF created in HTML format?

Currently, I am facing a challenge in generating PDFs using reportlab. The data that needs to be displayed is fetched from a dataframe. However, one field contains a lengthy text that requires breaklines for better readability in the PDF. Below is the sni ...

Struggling to reset the first item in an HTML select dropdown with Angular - any tips?

I am having an issue with my dropdown in a modal window. When I first open the modal, the dropdown works as expected. However, if I make a selection and then close and reopen the modal, the selected value remains instead of resetting to 'None selected ...

Ensuring that images are the perfect size for their parent container

Exploring the functionalities of angular bootstrap carousel, I am eager to showcase various images and enable clicking on them. The challenge I'm facing is that my images are not uniform in size and don't fit perfectly within my bootstrap column ...