1

With multiselect option set to true, I want to be able to copy paste values from an input field to another. Actually the paste event is trigering a kind of validation and always displaying the current day on the selection widget.

I've tried to set the forceParse option to false but it doesn't change anything. I've also look on the documentation but can't find an option for this problem, have I missed something ? Should I fork this package and modify the paste event myself ? I've seen a looooot of forks of this package on Github, maybe someone had the same issue ?

https://github.com/uxsolutions/bootstrap-datepicker

Cheers guys and thanks for your help.

$('.date').datepicker({
   multidate: true,
   format: 'yyyy-mm-dd',
   orientation: 'bottom',
   language: 'fr',
   forceParse: false,
});
AL_9000
  • 38
  • 6
  • are both input fields of class `.date`? – majidarif Jul 16 '19 at 14:50
  • nope, in fact you can see the official demo here : https://uxsolutions.github.io/bootstrap-datepicker/?markup=input&format=&weekStart=&startDate=&endDate=&startView=0&minViewMode=0&maxViewMode=4&todayBtn=false&clearBtn=false&language=en&orientation=auto&multidate=true&multidateSeparator=&keyboardNavigation=on&forceParse=on#sandbox Just try to pick multiple dates, copy them, and try to past them in the same exact input field – AL_9000 Jul 16 '19 at 14:52
  • probably should use another library if possible. – majidarif Jul 16 '19 at 15:11

1 Answers1

0

Workaround using paste event

Issue https://github.com/uxsolutions/bootstrap-datepicker/issues/1950

$('input').datepicker({
  multidate: true,
  format: 'yyyy-mm-dd',
  orientation: 'bottom',
  language: 'fr',
  forceParse: false,
});

$('input').on('paste', function(e) {
  this.value = new String(e.originalEvent.clipboardData.getData('text') || '')
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.standalone.min.css" integrity="sha256-jO7D3fIsAq+jB8Xt3NI5vBf3k4tvtHwzp8ISLQG4UWU=" crossorigin="anonymous" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js" integrity="sha256-bqVeqGdJ7h/lYPq6xrPv/YGzMEb6dNxlfiTUHSgRCp8=" crossorigin="anonymous"></script>

<input type="text">
User863
  • 19,346
  • 2
  • 17
  • 41
  • In fact it works with the code snipet but doesn't on my app. I can get the pasted value but can't assign it back to the input value ... – AL_9000 Jul 16 '19 at 15:14
  • @AL_9000 try placing the input binding before datepicker initialization and prevent the event – User863 Jul 16 '19 at 15:19
  • 1
    It was my jQuery selector that was wrong ... I don't know why, but the class selector wasn't working, but if I specify an id like that : `$('#datePickerInput')` it works ... Thanks a lot man ! – AL_9000 Jul 16 '19 at 15:53