Bootstrap datetimepicker don't work with readonly or disabled

风格不统一 提交于 2020-01-22 10:38:07

问题


I have a serious problem with bootstrap datetimepicker, Here is the jsfiddle :

<br/>
<!-- padding for jsfiddle -->
<div class="row">
    <div class="col-md-12">
         <h6>datetimepicker1</h6>

        <div class="form-group">
            <div class="input-group date" id="datetimepicker1">
                <input type="text" class="form-control" >   <span class="input-group-addon"><span class="glyphicon-calendar glyphicon"></span></span>
            </div>
        </div>
    </div>
</div>

The problem is that when i open my website in mobile, mobile keyboard triggered when i focus the input field so what i need is that only the datepicker show without keyboard. So for that i use readonly or disabled, but the problem is that when i use one of them the bootstrap datetimepicker doesn't work. http://jsfiddle.net/faissal_aboullait/kx0e5wmq/1/


回答1:


If your are still looking for a solution take a look at the snippet. This is exactly what i suggested in the comment, you just have to call datetimepicker with

ignoreReadonly: true

That's it.

$(function () {
  $('#datetimepicker').datetimepicker({
    ignoreReadonly: true
  });
});
.container {
  margin-top: 80px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>
<div class="container">
  <div class="row">
    <div class="col-sm-12">
      <div class='col-sm-6 col-sm-offset-3'>
        <div class="form-group">
          <div class='input-group date' id='datetimepicker'>
            <input type='text' class="form-control" readonly />
            <span class="input-group-addon">
              <span class="glyphicon glyphicon-calendar"></span>
            </span>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

Use the icon to pick your date not the text field. The text field is read only.




回答2:


This worked for me:

.bootstrap-datetimepicker-widget.dropdown-menu  {
    width: 100%;
    max-width: calc(100%) !important;
}


来源:https://stackoverflow.com/questions/30298208/bootstrap-datetimepicker-dont-work-with-readonly-or-disabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!