Trouble Integrating JQuery UI DatePicker into Bootstrap Card

I've built a Bootstrap 4 website with various survey questions grouped in Bootstrap Cards. One question requires a Date response, so I've implemented a JQuery-UI DatePicker for that purpose. However, upon selection, the DatePicker doesn't show up.

Interestingly, when I tested the DatePicker on a field outside of the card, it displayed correctly. Upon inspecting the element and manually changing the display property from "none" to "block", the DatePicker appeared. I even tried adjusting the z-index to 1060 (a common fix for similar issues with Modals), but unfortunately, it didn't resolve the problem.

Any suggestions?

The Card:

<div class="card card-default">
        <div class="card-header">
            <div class="card-title"><strong>2</strong> - Farm Resources</div>
        </div>
        <div class="card-wrapper">
            <div class="card-body">
                <div class="">

                    <div class="card-title"><strong>Q4</strong> - When did you last soil sample?</div>
                    <div class="input-group col-md-4 mb-3">

                        <input type="text" class="form-control hasDatepicker" id="validationCustomUsername">
                        <div class="input-group-append">
                            <span class="input-group-text" id="inputGroupPrepend"><i class="far fa-calendar-alt"></i></span>
                        </div>
                    </div>

                    <div class="card-title"><strong>Q5</strong> - How often on average are the fields soil sampled?</div>
                    <div class="col-md-4 mb-3">
                        <div class="form-check radio radio-primary">
                            <input class="form-check-input" type="radio" name="Q5" id="Q5_1" value="option1" checked="">
                            <label class="form-check-label" for="Q5_1">
                                0-3 years
                            </label>
                        </div>
                        <div class="form-check radio radio-primary">
                            <input class="form-check-input" type="radio" name="Q5" id="Q5_2" value="option2" checked="">
                            <label class="form-check-label" for="Q5_2">
                                3-6 years
                            </label>
                        </div>
                        <div class="form-check radio radio-primary">
                            <input class="form-check-input" type="radio" name="Q5" id="Q5_3" value="option3" checked="">
                            <label class="form-check-label" for="Q5_3">
                                6-10 years
                            </label>
                        </div>
                        <div class="form-check radio radio-primary">
                            <input class="form-check-input" type="radio" name="Q5" id="Q5_4" value="option4" checked="">
                            <label class="form-check-label" for="Q5_4">
                                10 years+
                            </label>
                        </div>
                    </div>

                    <div class="card-title"><strong>Q6</strong> - A question requiring selection from a dropdown?</div>
                    <div class="input-group col-md-4 mb-3">

                        <div class="form-group">
                            <select class="form-control" id="exampleFormControlSelect1">
                                <option>Please select</option>
                                <option>1</option>
                                <option>2</option>
                                <option>3</option>
                                <option>4</option>
                                <option>5</option>
                            </select>
                        </div>
                    </div>

                    <div class="card-title"><strong>Q7</strong> - Question with a slider?</div>
                    <div class="input-group col-md-4 mb-3">

                        <label for="amount">
                            Selected value:
                            <input type="text" id="amount" readonly="" style="border:0; color:#f6931f; font-weight:bold;width:50px;">
                        </label>
                        <div id="slider" style="width:100%;" class="ui-slider ui-corner-all ui-slider-horizontal ui-widget ui-widget-content"><span tabindex="0" class="ui-slider-handle ui-corner-all ui-state-default" style="left: 20%;"></span></div>
                    </div>
                </div>
            </div>
        </div>



    </div>

Javascript initialization for the datepicker:

$(function () {
    $("#validationCustomUsername").datepicker();

    $("#Date").datepicker();
});

Styling for the card (should adhere to the default Bootstrap styles):

.card {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
min-width: 0;
word-wrap: break-word;
background-color: #fff;
background-clip: border-box;
border: 1px solid rgba(0, 0, 0, 0.125);
border-radius: 0.25rem;
}

Answer №1

Make sure to exclude the hasDatepicker class from your input field. This class is added by jQuery UI after initialization, so adding it manually before can cause issues.

$(function () {
    $("#validationCustomUsername").datepicker();

    $("#Date").datepicker();
});
.card {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
min-width: 0;
word-wrap: break-word;
background-color: #fff;
background-clip: border-box;
border: 1px solid rgba(0, 0, 0, 0.125);
border-radius: 0.25rem;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">

<div class="card card-default">
        <div class="card-header">
            <div class="card-title"><strong>2</strong> - Farm Resources</div>
        </div>
        <div class="card-wrapper">
            <div class="card-body">
                <div class="">

                    <div class="card-title"><strong>Q4</strong> - When did you last soil sample?</div>
                    <div class="input-group col-md-4 mb-3">

                        <input type="text" class="form-control" id="validationCustomUsername">
                        <div class="input-group-append">
                            <span class="input-group-text" id="inputGroupPrepend"><i class="far fa-calendar-alt"></i></span>
                        </div>
                    </div>

                    <div class="card-title"><strong>Q5</strong> - How often on average are the fields soil sampled?</div>
                    <div class="col-md-4 mb-3">
                        <div class="form-check radio radio-primary">
                            <input class="form-check-input" type="radio" name="Q5" id="Q5_1" value="option1" checked="">
                            <label class="form-check-label" for="Q5_1">
                                0-3 years
                            </label>
                        </div>
                        <div class="form-check radio radio-primary">
                            <input class="form-check-input" type="radio" name="Q5" id="Q5_2" value="option2" checked="">
                            <label class="form-check-label" for="Q5_2">
                                3-6 years
                            </label>
                        </div>
                        <div class="form-check radio radio-primary">
                            <input class="form-check-input" type="radio" name="Q5" id="Q5_3" value="option3" checked="">
                            <label class="form-check-label" for="Q5_3">
                                6-10 years
                            </label>
                        </div>
                        <div class="form-check radio radio-primary">
                            <input class="for...

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

How can I make an image tag perfectly fit a CSS grid cell without using object-fit?

In this Vue component, the parent element displays 8 instances of these components in a 2x4 grid layout. The issue arises when the image within each component is larger than its container, causing it to not shrink to fit while maintaining the aspect ratio ...

CSS problem: Chrome scrolling overflow glitch (ghost margin/padding)

Hey there, I've run into a bit of an issue with two divs containing tables - one acting as a header and the other as a scrollable content area. Everything is working perfectly except for this mysterious border/margin that keeps appearing in Chrome on ...

Arranging Bootstrap divs vertically and then horizontally in mobile view

My website layout is relatively straightforward. It consists of a header at the top, a navigation bar with an image inside a column on the left, and the main content displayed on the right side. https://i.stack.imgur.com/yYzaG.png For mobile responsive vi ...

Textchanged event is interrupted by Datetimepicker

Typically, I am able to find solutions to any question here, but this one has me stumped. The issue arises when I switch my asp textbox to a (bootstrap) datetimepicker, the OnTextChanged event of the textbox fails to trigger at all. I'm not sure how ...

What is the procedure for eliminating the underline located at the bottom of the table?

Can anyone please assist me with removing the underlines at the end of the table? I find it quite unattractive and can't seem to figure out how to remove it. https://i.sstatic.net/stvHt.png https://i.sstatic.net/YYbrX.png Below is the code snippet ...

The scaling of the attribute element appears to be off-kilter

https://i.sstatic.net/QmE8k.png .customProgramTemplate { background-color: rgba(0, 0, 0, 0.75); width: 400px; height: 185px; border-radius: 8px; margin: auto; color: white; padding: 0; } .customProgramButton { text-decoration: none; t ...

Issue with iOS iframe scrolling - unable to scroll as expected

On iOS devices like the iPad and iPhone 6, scrolling doesn't seem to work as intended. Instead of the iframe scrolling, it's the 'body' that is moving. Javascript $(document).on(clickHandler, '#content a', function(){ href ...

Is it achievable to customize the appearance of links with identical classes but distinct title attributes?

Currently updating my website and unable to access the HTML directly. I'm curious if it's feasible to produce various hover effects for image links within parent divs that share the same name but have different title tags. Here is the code snip ...

Moving elements using CSS

Hi, I've been facing this issue with my web development since the start. Whenever I zoom in, the container also moves along. Is there any way to fix this problem? .darkslidecont{ width: 200px; height: 50px; position: relative; bac ...

Achieve a new line break when the user hits the "Enter" key using HTML and JavaScript

I'm in the process of developing a Chrome Extension that allows users to create a to-do list. My goal is to enable users to submit their task by pressing the "Enter" key, which should move the task to the next line after submission. I am currently fac ...

Tips for incorporating a datepicker into your Angular 2 application

In my HTML file, I have defined the following code: <span id="datepicker" (click)="ShowDate()"> <i class="fa fa-calendar " aria-hidden="true" style="margin-top: 20px;margin-left: 20px;" >< ...

Circular shapes inside a button created without using a canvas in HTML and JavaScript

I'm looking to design a button similar to the one demonstrated in this example. While I like how it appears, I prefer not to use canvas as it is not visually pleasing. Is there a way to achieve this without using canvas, or should I stick with it? Be ...

Unable to make changes to the code on the Google Maps API page

Hello! I am currently utilizing the Google Maps API on my website, pulling information for it using PHP. I have implemented some sample code but I am unable to modify it. Could you please assist me? Even just providing a header would be greatly appreciat ...

Conceal the block quotes while substituting with a newline

My HTML page contains numerous comments enclosed in blockquotes. I attempted to implement a feature that allows users to hide all the comments with just one click by using the following JavaScript code: const blockQuotes = document.getElementsByTagName(& ...

The Bootstrap drop-down feature refuses to open

I seem to be having trouble with a basic issue. I used the standard template from the bootstrap website, but for some reason, when I click on the dropdown menu in the navbar, it's not opening. Can someone help me figure out what's going wrong? & ...

Eliminate the excessive space surrounding the alert div by utilizing Bootstrap 4's spacing utilities

I am struggling with aligning the text in my Bootstrap 4 alert message with the top of the (i) icon. I have tried adjusting margins and padding without success. Can anyone provide guidance on how to achieve this alignment, as well as centering the card ver ...

Ways to deactivate a button using CSS

I need to use Javascript to disable a link based on its id. By default, the link is invisible. I will only enable the link when the specific id value comes from the backend. HTML <li id="viewroleId" style="display: none;"> <a href="viewrole" ...

Slanted background div that adjusts to the screen size

I'm struggling to create a slanted angle div that remains responsive as the screen size changes. Unfortunately, my current layout breaks completely when the screen gets bigger. If you'd like to take a look at what I've been working on so fa ...

My goal is to develop a PHP photo gallery using either an array, session variables, or cookies

I am in need of a solution for my issue. https://i.stack.imgur.com/Xe65l.png The image shows the front end, and I require a corresponding function to be developed for it. ...

Surprising Outcomes of Negative Margin in jQuery Animation

Unique Project Summary I am currently working on a website that incorporates a sliding menu feature. I have successfully implemented this functionality, and the display remains consistent during the animation transitions for sliding the menu in and out. T ...