Strategies for showcasing a dynamic date selection tool

I am facing an issue with a datepicker input inside a while loop for generating dynamic data. The problem is that the datepicker only seems to work on the first input. How can I rectify this?

Here is my blade:

    <div class="row">
    @foreach ($kelas as $x)
        <div class="col-6">
            <div class="card">
                @include('flashmessage')
                <div class="card-body">
                    <p style="font-weight: 800;"> Nama Kelas : {{ $x->nama_kelas }} - {{ $x->matkul }} </p>
                    <p style="font-weight: 800;"> Nama Modul : {{ $x->modul }} </p>
                    <div class="col-md-12">
                        <div class="mb-3">
                            <label class="form-label">Tanggal Praktek</label>
                            <div class="input-group">
                                <input type="text" class="form-control" placeholder="dd M, yyyy" data-date-format="dd M, yyyy" 
                                                data-date-container='#datepicker' data-provide="datepicker" id="datepicker{{$x->id_modulkelas}}">

                                <span class="input-group-text"><i class="mdi mdi-calendar"></i></span>
                            </div><!-- input-group -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    @endforeach
</div>

This will create multiple rows with a datepicker input for each data entry in $kelas. And here is my JavaScript script:

    <script>
    $( function() {
      $( "#datepicker{{$x->id_modulkelas}}" ).datepicker();
    } );
</script>

I have tried adding unique IDs as shown above. Currently, the datepicker only appears on the first row input. When I click on another input, the datepicker does not appear. How can I ensure the datepicker appears on all row inputs?

https://i.sstatic.net/3jVE7.png

Answer №1

It appears that you have assigned the same ID to all your datepicker inputs, which could be causing issues. IDs should always be unique. Consider updating your blade file in the following way:

<div class="row">
    @foreach ($classes as $class)
        <div class="col-6">
            <div class="card">
                @include('flashmessage')
                <div class="card-body">
                    <p style="font-weight: 800;"> Class Name : {{ $class->class_name }} - {{ $class->subject }} </p>
                    <p style="font-weight: 800;"> Module Name : {{ $class->module }} </p>
                    <div class="col-md-12">
                        <div class="mb-3">
                            <label class="form-label">Practice Date</label>
                            <div class="input-group">
                                <input type="text" class="form-control datepicker" placeholder="dd M, yyyy" data-date-format="dd M, yyyy" data-date-container='#datepicker1' data-provide="datepicker">
                                <span class="input-group-text"><i class="mdi mdi-calendar"></i></span>
                            </div><!-- input-group -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    @endforeach
</div>

Update your script as follows:

<script>
    $(function() {
        $(".datepicker").datepicker();
    });
</script>

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

Resetting an Angular Material select component

I've encountered an issue with Angular Material. Currently, I have a form with two select elements. The problem arises when I choose a value in one of the selects, it resets and loses its value. Could this be a bug? Or am I possibly making a mistake ...

Is it possible to submit two forms simultaneously using jQuery or AJAX?

My plan is to save 2 forms, with the first form providing the Foreign key for the second form. This is my attempt at saving this using JavaScript: $("#btnSave").click(function (e) { e.preventDefault(); $('#workForm').submit(); ...

Error: The function getAuth has not been defined - Firebase

I have included the code snippets from index.html and index.js for reference. The analytics functionality seems to be working fine, but I am facing an issue with authentication due to an error during testing. Thank you for your help. index.html <script ...

Smoother transitions with spline curves in Three.js

My current project involves drawing a CubicBezierCurve3 curve in three js. However, I want to enhance the drawing process by visualizing it as a moving rocket leaving behind a gas trail. Rather than having the entire curve drawn at once, I aim to draw it p ...

Delay in Ionic list item navigation

As I continue to build my app using "$ ionic start myApp sidemenu" and deploy it directly to Android, I've noticed a significant delay when tapping on the playlist page, such as when selecting "Indie". It feels like there is a 300ms lag before the pag ...

discovering obscured information using jquery

I am working on a code snippet where I need to hide the detailed content for display purposes and only show it during printing: <div> <ul> <li> <span style="font-size: 1.25em;"> <strong> ...

jqGrid is failing to display basic JSON data properly

As a newcomer to Jquery and Json, I am struggling with binding a JSON object from a RESTful Webservice written in WCF to jqGrid. Despite saving the JSON object as a static file and attempting to bind it to the grid, I realized that the issue does not lie w ...

Can anyone suggest methods for displaying query data from a JSON file using HTML?

After countless hours of searching through various forums, I have attempted numerous methods to display query data from a JSON file onto an HTML page. My initial attempt was using XmlHttpRequest, which yielded no results. I then tried utilizing jQuery, sp ...

Fluctuate the window.location with jQuery or javascript

My goal is to create a functionality where clicking an image will toggle the window.location url between '#' and '#footer'. The current code I have for this is: <script> function clickarrow(){ var rd=Math.floor(Math.random() ...

Tips on incorporating a firebase object into your Angular application using $scope

As a beginner in coding, I would greatly appreciate a simple answer. I am attempting to treat a Firebase object as a JavaScript array for use in HTML via $scope. What is the most effective approach? Database: database Current code: var mainApp = angula ...

Angular directive ceases to trigger

I am currently working on implementing an infinite scrolling directive. Initially, when the page loads and I start scrolling, I can see the console log. However, after the first scroll, it stops working. It seems like it only triggers once. Can anyone poi ...

Thumbnail Option in the WordPress Media Uploader

Is it possible to add support for selecting image size (thumbnails) in the Media Library popup created using the wp.media() function in WordPress? I am currently using WordPress 4.5.2 and my code sample is as follows: wp.media.frames.selectFile=wp.media( ...

Chess.js TypeScript declaration file for easy implementation

Currently, I am delving into learning typescript and have taken up the challenge of crafting a declaration file for the chess.js library. However, it seems that I am struggling to grasp the concept of creating one. Whenever I attempt to import the library ...

Is there an issue with the functioning of Angular routing?

I've been working on setting up routing in AngularJS and it seems like the server is running smoothly. However, I'm facing an issue with the angular routing not functioning correctly; only the main.html page loads in ng-view, while second.html do ...

Alter the Vue view using an object instead of the url router

Currently working on a chrome extension using Vue.js where I need to dynamically update views based on user interactions. Usually, I would rely on the Vue Router to handle this seamlessly... however, the router is tied to the URL which poses limitations. ...

Every time I click, the click event is getting attached repeatedly through the on method

Here is the HTML code that I am working with: <div class="connect"> <ul> <li><a href="#">Assign a Task</a></li> <li><a attr="viewCard" href="#">View Ca ...

Script in Javascript halting Internet Explorer's operation

I'm encountering a problem with Internet Explorer freezing due to the following code. This code is part of a project that focuses on handling student grades: var array1 = StudentGradeAreadHugeList(); var nextArrayItem = function() { var grade = ...

What steps should be followed to execute this moment.js code in an Angular.js controller using Node.js?

I am trying to adapt the following node.js code that uses moment.js into an AngularJS controller: var myDate = new Date("2008-01-01"); myDate.setMonth(myDate.getMonth() + 13); var answer = moment(myDate).format('YYYY-MM-DD'); To achieve this, I ...

Exclude the file and directory patterns from being watched with PM2: ignore folder

I need help with configuring pm2 to stop monitoring folders that have names like cache or tmp. I've tried multiple approaches in my app.json configuration file: {"apps": [{ "name": "BSTAT", "script": &q ...

Enhancing JSON Objects in AngularJS with Custom Properties and Calculations

Hello, I'm still getting the hang of angularjs and could use some guidance. I have a Rest service that provides data on saleItems when a get request is made, as shown below: saleItems = [ { "id": 236, "variant": "Oval Holder", "mrp": "6 ...