Problems with the JQuery-UI DatePicker Calendar, it stays open when setting a setDate when loading my page

0

I am using the function datepicker() of JQuery-UI and I have programmed it so that when loading my page it shows me the current date in an input HTML .

JavaScript code

$(document).ready(function(){
 $("#fecha-ticket").datepicker({
changeMonth:true,
changeYear: true,
dateFormat: "dd-mm-yy"}).datepicker("setDate", new Date());
$("#fecha-ticket").datepicker("hide");

$('#iconoCal').click(function() {
$("#fecha-ticket").focus();
});

});

The date is shown in the input as it should be:

But when doing the above, leave the calendar open at the bottom of my page.

What I would like to know is how or in what way can I show the current date without leaving the datepicker open?

  

Try using: datepicker( "hide" )

    
asked by Ferny Cortez 08.02.2018 в 04:45
source

1 answer

0

Honestly the information you give us is very little to solve your error but I think that using this tag instead of datepicker () could solve your problem. You only add the bootstrap css and there will be no problem

$(document).ready(function(){         
  var now = new Date();

  var day = ("0" + now.getDate()).slice(-2);
  var month = ("0" + (now.getMonth() + 1)).slice(-2);

  var today = now.getFullYear()+"-"+(month)+"-"+(day) ;

  $('#date').val(today);
});
<HTML>
    <HEAD>
        <TITLE>Título de la página</TITLE>
    </HEAD>

    <BODY>
        <input id="date" type="date" val="now">
    </BODY>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</HTML>
    
answered by 08.02.2018 в 21:54