21

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/

ketan
  • 18,500
  • 41
  • 58
  • 88
Codinga
  • 560
  • 3
  • 11
  • 27
  • possible duplicate of [prevent iphone default keyboard when focusing an ](http://stackoverflow.com/questions/7610758/prevent-iphone-default-keyboard-when-focusing-an-input) – DavidDomain May 18 '15 at 08:25
  • No because i need a solution for all mobile cases. android and iphone or others – Codinga May 18 '15 at 08:27
  • The post that you talking about is resolved by puting readonly. My post is that this readonly is a the probleme Look at this please : http://jsfiddle.net/faissal_aboullait/kx0e5wmq/1/ – Codinga May 18 '15 at 08:28

4 Answers4

60

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.

DavidDomain
  • 14,454
  • 4
  • 43
  • 50
  • Did you take a look at the snippet? If you open the console in your fiddle it says "ignoreReadonly is not recognized!". That's because you are using a different version of datetimepicker. Just use the dependencies from my snippet and it will work just fine. – DavidDomain May 19 '15 at 08:29
  • I can't change dependencies because i use a theme with this plugin. there is an other solution without changing dependencies? – Codinga May 19 '15 at 09:35
  • You might only have to change the datetimepicker, did you try that? You are already using version 4 of datetimepicker, the build in my snippet is version 4.7.14. So this should not break anything in your theme. Try it out and cross fingers. Whether you are using a theme or not, if you think my answer is a solution to the problem in general you might want to accept the answer for others that might stumble over the same problem. – DavidDomain May 19 '15 at 09:55
  • You convinced me, tested and it work good in my code. I accepted your answer as the right one. Tnx man – Codinga May 19 '15 at 11:01
  • Works perfectly! Thank you. – tmthyjames Oct 01 '15 at 16:12
  • 1
    i search many times, but when i saw this answer, i went back to bootstrap datetimepicker docs, i am too late to realize :D.. upvote for that – stryker Dec 09 '15 at 08:18
  • Thank you very much, it works immediately haha. Greetings from Chile. – Cristian Meza Jun 29 '16 at 20:13
  • Sir, you saved me lot of hours!! – FonzTech Jul 19 '19 at 20:20
1

The clause readonly="yes" in put statement is workable, actually required libraries are not included, that are as following ones

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">  
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet">  
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>  
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js">    
</script>
M Nasir
  • 11
  • 1
0

This worked for me:

.bootstrap-datetimepicker-widget.dropdown-menu  {
    width: 100%;
    max-width: calc(100%) !important;
}
Webmaster G
  • 482
  • 5
  • 11
0

Following clause is workable, if it is not working it simply means required libraries are not included, that are as following ones

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">  
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet">  
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>  
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js">    
</script>
M Nasir
  • 11
  • 1
  • readonly="yes" in input statement is workable with following libraries. – M Nasir Apr 27 '21 at 10:27
  • You've added the same answer twice. can you remove one of them please? additionally, can you explain why your answer is better than the accepted answer? – Jad Apr 27 '21 at 12:05