0 votes

Bootstrap Datepicker, get the date by clicking on a calendar day when in "embeded" mode

I'm using Bootstrap Datepicker created through the Sandbox page in embeded mode, that is to say that by default it is displayed on the page as shown in the screenshot. datepicker

I specify the version I use:

/*!
 * Datepicker for Bootstrap v1.9.0 (https://github.com/uxsolutions/bootstrap- 
datepicker)
 *
 * Licensed under the Apache License v2.0 
(http://www.apache.org/licenses/LICENSE-2.0)
 */

and the code:

<div class="row" id="sandbox-container">
  <div class="col-12"></div>
</div>

$(document).ready(function() {
    $('#sandbox-container div').datepicker({
        weekStart: 1,
        todayBtn: "linked",
        language: "es",
        daysOfWeekDisabled: "0,6",
        todayHighlight: true
    });
});

I need that when I click on any day I get an alert with the specific date of that day, month and year. I have seen a Fiddle that solves the problem, but it seems that it is not a current version because the options do not work. Does anyone know how I can get those values?

1voto

Reviewing the documentation an event called changeDate when the user selects a date, the event handler is as follows

$('.datepicker').datepicker()
   .on("changeDate", function(e) {

});

Modifying your code would look like this

$(document).ready(function() {
  $('#sandbox-container div').datepicker({
      weekStart: 1,
      todayBtn: "linked",
      language: "es",
      daysOfWeekDisabled: "0,6",
      todayHighlight: true
  }).on("changeDate", function(e) {
     alert("Seleccionaste " + e.date.getDate() + " de " + e.date.getMonth() + " del " + e.date.getUTCFullYear());
  });
});

I leave you a enlace of the working example, using version 1.9.0 of Datepicker for Bootstrap.

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X