从>出发到签入/签出

时间:2019-03-28 11:19:22

标签: javascript html datepicker pickadate

我正在使用Pickadate(3.5.6)构建一个表单以用于签入和签出,用户可以在其中选择到达和离开的日期。

我希望将结帐表格自动设置为到达月份,很遗憾,此脚本无法正常工作。

使用我的脚本,日历无法打开,并且未加载Pickadate

有什么建议吗?

HTML:

<input type="date" name="checkin" class="form-control calendario datepic campo" required="" placeholder="Check-in" autocomplete="off" id="input_from">
                <span class="form-label">Check-In</span>
                <input type="date" name="checkout" class="form-control calendario datepic" required="" placeholder="Check-out" autocomplete="off" id="input_to">
                <span class="form-label">Check-Out</span>

JAVA:

  $.extend($.fn.pickadate.defaults, {
    monthsFull: ['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'],
    weekdaysShort: ['Dom', 'Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab'],
    weekdaysFull: [ 'Domenica', 'Lunedi', 'Martedi', 'Mercoledi', 'Giovedi', 'Venerdi', 'Sabato' ],
    today: 'Oggi',
    clear: 'Cancella',
    close: 'Chiudi',
    firstDay: 1,
    formatSubmit: 'yyyy-mm-dd',
    hiddenName: true,
    labelMonthNext: 'Mese successivo',
    labelMonthPrev: 'Mese precedente',
    labelMonthSelect: 'Seleziona un mese',
    labelYearSelect: 'Seleziona un anno',
    min: true,
  });

    var from_$input = $('#input_from').pickadate(),
    from_picker = from_$input.pickadate('picker')

    var to_$input = $('#input_to').pickadate(),
    to_picker = to_$input.pickadate('picker')


    // Check if there’s a “from” or “to” date to start with.
    if ( from_picker.get('value') ) 

    {        
       var today = new Date($('#input_from').val());
       today.setDate(today.getDate() + 1)
      to_picker.set('min', today)
    }
    if ( to_picker.get('value') ) 
    {
       var today = new Date($('#input_to').val());
    today.setDate(today.getDate() - 1)
      from_picker.set('max', today)


    }
    // When something is selected, update the “from” and “to” limits.
    from_picker.on('set', function(event) 
    {

      if ( event.select ) 
      {
         var today = new Date($('#input_from').val());
    today.setDate(today.getDate() + 1)
        to_picker.set('min', today)    
      }

      else if ( 'clear' in event ) 
      {

        to_picker.set('min', false)
      }

    })

    to_picker.on('set', function(event) 
    {
      if ( event.select ) 
      {
        var today = new Date($('#input_to').val());
    today.setDate(today.getDate() - 1)
        from_picker.set('max', today)
      }
      else if ( 'clear' in event ) 
      {

        from_picker.set('max', false)
      }
    })


0 个答案:

没有答案