简体   繁体   English

第二个datePicker不能选择一个小于第一个datePicker的日期

[英]Second datePicker can not select a date less than the first datePicker

As a title I have implemented two datePicker within my project, my goal is that the second datePicker can not select a date before the date selected in the first datePicker. 作为标题,我在项目中实现了两个datePicker,我的目标是第二个datePicker无法选择在第一个datePicker中选择的日期之前的日期。

code: 码:

    <div class="col-md-4">
    <form name="NOME_FORM" method="post" action="registra_campagne.php" class="text-center border border-light p-5" onsubmit="return validateForm()">
    <p class="h4 mb-4">Durata Campagna</p>
    <div class="md-form">
    <!--The "from" Date Picker -->
    <input name="data_inizio" placeholder="Data inizio" type="text" id="date-picker-example" class="form-control datepicker">
    <label for="date-picker-example">Inizio</label>

    </div>
    <div class="md-form">
    <!--The "to" Date Picker -->
    <input name="data_fine" placeholder="Data Fine" type="text" id="date-picker-example2" class="form-control datepicker">
    <label for="date-picker-example2">Fine</label>
    </div>
    <input class="btn btn-info btn-block" name="submit" type="submit" value="Aggiungi"><br>
    </form>
    </div>
    <script type="text/javascript">




    // Data Picker Initialization
    $('.datepicker').pickadate({
    min : new Date(),
    onClose: function(){
    $('#date-picker-example2').pickadate({
    min : $('.datepicker').val()
    })
    }
    });


    $('.datepicker').pickadate({
    // Escape any “rule” characters with an exclamation mark (!).
    format: 'yyyy/mm/dd',
    formatSubmit: 'Y/m/d',
    hiddenPrefix: 'prefix__',
    hiddenSuffix: '__suffix'
    })


    $('.datepicker').pickadate({
    closeOnSelect: false,
    closeOnClear: false

    });
    $('#input_starttime').pickatime({
    twelvehour: true

    });
    $('#input_endtime').pickatime({
    darktheme: true,
    twelvehour: false

    });
    </script> 

I would be very grateful because up to now the only feature implemented is that the user who uses the datePicker, can not select a date before the current date 我将不胜感激,因为到目前为止,唯一实现的功能是使用datePicker的用户无法选择当前日期之前的日期

I have had the displeasure to go through the documentation for the datepicker. 我不满意要查看有关日期选择器的文档。 It is not very easy to understand, but the datepicker itself is well done, still beats any native alternative. 这不是很容易理解,但是日期选择器本身做得很好,仍然胜过任何本机替代方案。

His is what you need to set and some extra tips: 他是您需要设置的内容以及一些其他提示:

$("#date2").datepicker({ // initialization, you pass an option object to the datepicker function
changeMonth: true,          // with this you can change months on click

changeYear: true,            //  change year on click

yearRange: "1930:2018",       // your year range , this is what you need
showAnim: "slide",            // give the datpicker calendary UI an animation
onSelect: calcDiff,           // here you can pass you own callback functions, this is mine, you do not need this
onClose: move,                 // another of my own

minDate: null,                 // do not set this if you want to limit the range
maxDate: null                   // do not set this
});

All you need is yearRange: "1930:2018" in the options object. 您需要做的是options对象中的yearRange:“ 1930:2018”。

You can check this one out, the upper one is a datepicker instance, the bottom is the very poor HTML/JS implementation 您可以检查一下,上面一个是datepicker实例,下面是非常差的HTML / JS实现

https://codepen.io/damPop/pen/oayEdg?editors=0010 https://codepen.io/damPop/pen/oayEdg?editors=0010

Ok, here is another, shorter codepen: 好的,这是另一个较短的codepen:

https://codepen.io/damPop/pen/vQbprR?editors=1010 https://codepen.io/damPop/pen/vQbprR?editors=1010

line 8 you set the range for the first datepicker instance, yearRange: "1990:2010". 在第8行中,您为第一个日期选择器实例yearRange设置了范围:“ 1990:2010”。

On line 28 you do the same for the second input element, yearRange: "1991:2010" 在第28行中,对第二个输入元素yearRange执行相同的操作:“ 1991:2010”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法 select 日期选择器中的第二个日期 - Unable to select second date in datepicker 如何在剑道日期选择器上显示小于最小日期或大于最大日期的日期 - How can I show a date on a kendo datepicker which is less than min date or greater than max date jQuery datepicker:基于第一个日期选择器选择第二个日期选择器的值 - Jquery datepicker : Selecting the value for second datepicker based on first date picker 在第二个日期选择器之后设置第一个日期选择器中的日期时,更新日期选择器中的日期(角度) - Updating date in Datepicker (Angular) when date in first datepicker is set after second datepicker Twitter Bootstrap Datepicker-开始日期小于结束日期 - Twitter bootstrap datepicker - start date less than end date 显示开始日期小于结束日期 - Datepicker - Displaying Start date less than End date - Datepicker 引导日期选择器:第二个字段,允许日期晚于第一个字段中的所选日期 - Bootstrap datepicker: second field to allow dates later than the selected date on first field Datepicker jQuery选择第一个日期后设置第二个日期 - Datepicker Jquery Set Second Date After Choosing First Date 将第一个日期选择器设置为比第一个日期选择器提前一年 - Setting second datepicker a year ahead of the first datepicker 无法在Foundation DatePicker中选择当前日期 - Can't select current date in Foundation DatePicker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM