0

Datepicker keeps on opening after selecting a date, how to prevent opening datepicker after choosing the date?

$("#dateload").datepicker({
    dateFormat: 'mm-dd-yy'
});

I tried with autoclose property to true but did not worked. I also tried with on change event to hide the datepicker, also not worked.

Theodore K.
  • 5,058
  • 4
  • 30
  • 46
Earth
  • 3,477
  • 6
  • 37
  • 78
  • 1
    It means the user can't correct his input. What is the reason you want to do that? Why don't you implement a button, where the user can confirm the chosen date is right. By firing this button you could run a function that disables the datepicker. In my opinion this would have better user experience. – cezar Apr 20 '17 at 13:35
  • check this [link](http://stackoverflow.com/questions/7812063/jquery-datepicker-readonly) – Ryad Boubaker Apr 20 '17 at 13:36

3 Answers3

0

I would go with this. (Demo here: http://codepen.io/8odoros/pen/OmNMVy)

 $( "#dateload" ).datepicker({
    dateFormat: 'mm-dd-yy',
    onSelect:function(){      
        if($(this).datepicker("getDate")) $(this).datepicker("destroy");
    }
  });
Theodore K.
  • 5,058
  • 4
  • 30
  • 46
0

Try to use this on change event handler.

$('#dateload').datepicker({
  format: 'mm-dd-yy'
}).on('change', function(){
    $('#dateload ~ .ui-datepicker').hide();
});
Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128
0

You can try to hide the dates after date changes like this

 $('#dateload').datepicker({
      format: 'mm-dd-yy'
    }).on('change', function(){
        $('.datepicker').hide();
    });
Islam Zedan
  • 656
  • 4
  • 21