Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

javascript - Disable minutes selection in Bootstrap Datetimepicker

I wan't datetimepicker to show only rounded hours and disable minutes selection. So user will be able to pick only hours, like 02:00. However I can't achieve this simple task. Here is my code (in a Laravel view):

$("#date_from").datetimepicker({
    format: 'yyyy-mm-dd hh:00',
    startDate: "{{date('Y-m-d')}}",
    minuteStepping: 60,
    autoclose: true }).on('hide', function(e) {
        $("#date_to").datetimepicker(
            "setStartDate", new Date($('#date_from').val())
         )....

I've tried steps: 60, stepping:60, minView: 1 and others. Still I'm getting this enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is one example for you, i think it will help you.

jsfiddle.net/tmk0293z/7/

There is changedate event bind with a function and changes the another startdate of other field.

Thanks, Nishit Zinzuvadiya

Here is the actual code (HTML):

<div class="input-append date form_datetime" id="first">
<input type="text" value="" readonly>
<span class="add-on"><i class="icon-th"></i></span>
</div>
<div class="input-append date form_datetime" id="second">
    <input type="text" value="" readonly>
    <span class="add-on"><i class="icon-th"></i></span>
</div>
<span id="selected"></span>

JS:

 $(".form_datetime").datetimepicker({
   format: "dd MM yyyy - hh:ii",
   minView:1,
   autoclose:true
 });

 $("#first").datetimepicker().on("changeDate", function(e){     
  var first = new Date(e.date.setMinutes(0));
        first.setHours(first.getHours()+first.getTimezoneOffset()/60); //timezone correction

  $("#second").datetimepicker('setStartDate', first); 

  //other = $("#first").find("input").val(); 
  //$("#second").datetimepicker('setStartDate', other); //works also

 });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...