Troublesome behavior from Bootstrap's datepicker

Recently, I decided to dive into front-end development using Bootstrap but I'm facing some challenges.

There are two issues here.

  1. The calendar glyph is appearing under the date input field instead of at the end of it on the same line.
  2. The picker is supposed to be auto-closing, but it's not functioning as expected.

I would appreciate any help with this. Below is the code of the page that is causing the problems:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Add Job</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <link href="css/bootstrap.min.css" rel="stylesheet"/>
        <script src="/bootstrap.min.js"></script>
        <script src="/jquery-3.7.0.min.js"></script>
        <script src="/bootstrap-datepicker.min.js"></script>
        <link href="css/datepicker.css" rel="stylesheet"/>
        <link href="css/all.min.css" rel="stylesheet"/>
    </head>
    <body>
        <script type="text/javascript">

            $('#datepicker').datepicker({
                            autoclose: true,
                            format: 'yyyy-mm-dd',
                            todayHighlight: true});
        </script>
        <nav class="navbar navbar-expand-sm bg-dark navbar-dark">
            <div class="container-fluid">
                <a class="navbar-brand" href="/">Jobs</a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#collapsibleNavbar">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="collapsibleNavbar">
                    <ul class="navbar-nav">
                        <li class="nav-item">
                            <a class="nav-link" href="#">Link1</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">Link2</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/newjobform">Add Job</a>
                        </li>  
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">View</a>
                            <ul class="dropdown-menu">
                                <li><a class="dropdown-item" href="/jobslastten">Last jobs</a></li>
                                <li><a class="dropdown-item" href="/jobs">All jobs</a></li>
                                <li><a class="dropdown-item" href="/jobsnext">Next jobs</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
        <div class="container">
            <div class="page-header" id="banner">
                <div class="row">
                    <div class="col-lg-8 col-md-7 col-sm-6">
                        <div class="row">
                            <div class="col-lg-6 col-md-7 col-sm-6">
                                <h1>Add a Job</h1>
                                <form action="/addjob" method="post"
                                                             enctype="multipart/form-data" class=
                                                                                           "form-horizontal">
                                    <fieldset>
                                        <div class="form-group" data-provide="datepicker">
                                            <label class="col-lg-3 control-label">
                                            Date</label>
                                            <input type="text" placeholder="YYYY-MM-DD" class="form-control">
                                            <span class="input-group-append input-group-addon"><span class="input-group-text"><i class="fa fa-calendar"></i></span></span>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-lg-3 control-label">Place
                                            </label>
                                            <div class="col-lg-9">
                                                <input type="text" class="form-control" name=
                                                                          "place" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class=
                                            "col-lg-3 control-label">Amount</label>
                                            <div class="col-lg-9">
                                                <input type="text" class="form-control" name=
                                                                          "amount" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-lg-12 col-lg-offset-3">
                                                <button type="submit" class="btn btn-primary"
                                                                      name="button">Create</button>
                                            </div>
                                        </div>
                                    </fieldset>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>

Answer №1

To align the Font Awesome icon to the right within an inline layout, it is recommended to enclose the text box and the input-group-append div with an additional div having the class input-group. Also, the deprecated input-group-addon class has been removed in favor of Bootstrap 3.

The automatic closing functionality of the date picker can be ensured by eliminating the

data-provide="datepicker"
attribute from the form-group div.

A correction was made to the script loading sequence, as the jQuery library should precede the Bootstrap JS file due to its dependency for proper functioning.

$("#datepicker").datepicker({
    autoclose: true,
    format: 'yyyy-mm-dd',
    todayHighlight: true
});
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.10.0/css/bootstrap-datepicker.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.10.0/js/bootstrap-datepicker.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/js/bootstrap.min.js"></script>

<div class="container-fluid">
  <div class="row">
    <div class="form-group col-sm-5 col-md-3 col-lg-2">
      <label class="col-lg-3 control-label" for="datepicker">Date</label>
      <div class="input-group">
        <input id="datepicker" type="text" placeholder="YYYY-MM-DD" class="form-control" readonly style="background: transparent">
        <div class="input-group-append">
          <span class="input-group-text" style="padding: 0.65rem 0.75rem; border-top-left-radius: 0; border-bottom-left-radius: 0"><i class="fa fa-calendar"></i></span>
        </div>
      </div>
    </div>
  </div>
</div>

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

Tips on customizing the appearance of React rendering components

<div> <h3>{this.props.product.name}</h3> <h3>{this.props.product.code}</h3> {this.renderColors()} <article> <div da ...

Dynamic Navbar that Adapts to Your Scroll

I'm experiencing an issue with my navbar. I want it to stay at the top of the page when I scroll, but whenever I apply the "position: fixed;" property, the navbar disappears. Below is my HTML and CSS code: <nav> <div class="navbar"> <b ...

Website loses its css after printing

I'm having trouble printing a website with a simple layout featuring two columns, each containing tables. The website I want to print is located at the following link: . However, when I try to print it using the JavaScript function window.print(), the ...

Methods for animating .jpg images using CSS

I'm currently working on animating an image, specifically moving it from left to right and back. However, before I dive into implementing CSS animation keyframes, I noticed that I am having trouble getting the HTML element to follow the CSS styles I a ...

Retrieve the row id from the table by clicking on a button in a modal box using jQuery

I am encountering a challenge with a small task due to my limited experience in jQuery. I have a table where each row has an icon. When the icon is clicked, a modal box appears with some content. After closing the modal box, I want to retrieve the table ro ...

Enhancing WordPress Icons for Parent and Child Elements

I am seeking to customize icons on a WordPress website. The site contains a variety of product categories, including subcategories. https://i.sstatic.net/sTm1O.png My goal is to display one icon for parent categories and a different icon for child catego ...

I have been working on creating a horizontal menu, but encountered an issue where the nav tag is unable to accommodate all the ul lists within itself

My latest project involves a menu with three separate divs: logo, nav-bar, and right-bar. I decided to use justify-content: space-around to position the elements - the logo on the left, navigation in the center, and right-bar on the right. However, when I ...

Is there a method to exclude children objects from spring animations during application?

Is it possible to create a fading in and out effect for a div (for example, to cycle through different backgrounds) while keeping its children (such as text) visible at full opacity at all times? {transitions((style, <animated.div class={ bg[i] + ...

Enhance jQuery event handling by adding a new event handler to an existing click event

I have a pre-defined click event that I need to add another handler to. Is it possible to append an additional event handler without modifying the existing code? Can I simply attach another event handler to the current click event? This is how the click ...

Is there a child missing? If so, add a class

I need to add the class span.toggle if the parent element of li does not have a child ul element. click here to view on codepen Snippet of HTML: <html lang="en"> <head> <meta charset="UTF-8> <title>No Title</title>& ...

"Creating eye-catching popup images in just a few simple steps

<div className="Image popup"> <Modal isOpen={modalIsOpen} onRequestClose={closeModal} contentLabel="Image popup" > <img src="../img/navratri-1.png" alt="Image popup" /> <b ...

Differences between -webkit- and -moz-transition

My website uses CSS3 transitions and I have noticed that the -webkit- prefix works, but the -moz- prefix does not seem to be working. This is the CSS code I am using: article {z-index: 2; float: left; overflow: hidden; position: relative; -webkit-transit ...

What is the best way to create a sliding motion to the right for a menu item, accompanied by a line when it

Is there a way to align the line to the right of the text when it's not selected, and have a new line appear on the left side that pushes the text and removes the line on the right side? Here is the design I'm trying to emulate. If you click t ...

Styling columns to be inline-flex without taking up the full height

I'm currently working on a project similar to "Trello" or "Zenhub," using a Kanban board with 4 columns placed in a div#board. The columns are set to display: inline flex, creating a neat horizontal alignment. However, I encountered an issue where eac ...

How to Keep PHP Include Visible within the div using Bootstrap 4

I utilized PHP include to add the information inside the modals for the albums, but it is not hidden as specified in the div class where it is included. You can check out the music page on . However, here is the code snippet for the music page where I in ...

How can we stop a form from being submitted when the input field is

Similar Question: How to prevent submitting the HTML form’s input field value if it empty <?php include '../core/init.php'; if(isset($_POST['nt']) && isset($_POST['ntb'])){ mysql_query("INSERT INTO `pos ...

tips for scrolling divs horizontally within the main container

I've been attempting to scroll horizontally, but even though the scroll bar is visible, it's not functioning. Here's the code: <!DOCTYPE html> <html> <head> <title>qwe</title> </head> <body> < ...

Discover the value of $(this) while working with dynamically generated elements in jQuery

Suppose I have a dynamic list created via AJAX, with li elements: ​<ul id="dynamic-list"> <li data-label="label1" >Label 1</li> <li data-label="label2" >Label 2</li> <li data-label="label3" >Label 3</l ...

The process of altering a span label's class with JavaScript

I am currently working with an HTML element that looks like this: <dd><span class="label label-success" id="status">Production</span></dd> My goal is to update it to: <dd><span class="label label-warning" id="status"> ...

Can the countup jQuery functions be adjusted to incorporate commas?

Is there a way to adjust the code below in order to add commas to the output? For instance, how can we make 300000 display as `300,000'? Here's the HTML: <span class="number counter" data-count="300000">300,000</span> And now for t ...