1

I am in trouble getting inputs types date and time to work on mobiles. I am getting double picking tools on mobiles (the native one and the JQuery UI) one and it won't let me complete the form, because datepicker won't hide. How can I prevent the JQuery UI picker to be displayed on mobiles that has native picking tool? example

This is the sample code I have:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="css\jquery-ui.min.css">
<script src="js\jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.6.3/jquery-ui-timepicker-addon.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.6.3/jquery-ui-timepicker-addon.min.js"></script>

<form class="form-horizontal" method="post" action="seleccionar_detalles.php">
    <div>
        <input type="date" id="lala" classs="fecha1" name="lala">
        <input type="time" placeholder="Salida" id="salida" name="Fecha_de_salida[]" />

    </div>
    <div class="form-group col-xs-24">
        <div class="col-xs-6 pull-right">
            <button type="submit" class="btn btn-siguiente">Submit</button>
        </div>
    </div>
</form>

<script>
    $('#salida').timepicker();
    $( ".fecha1" ).datepicker();
</script>
  • So you want to suppress datepicker when it's a mobile device, like iPhone? Would an `if` statement be enough? – Twisty Jun 09 '17 at 03:04

1 Answers1

0

You are using a input type="date", The jQuery-UI Datepicker uses a input type="text":

From the jQuery-UI Datepicker Documentation:

<p>Date: <input type="text" id="datepicker"></p>

This way you can avoid the double picking tools.

If you need to suppress the jQuery-UI Datepicker on mobile devices, you may use one of the mobile-device detection techniques described here: What is the best way to detect a mobile device in jQuery? and toggle the input type, like this:

$(document).ready(function() {
  var isMobile = ....
  // HTML 5 input types: date, datetime, datetime-local, month, time, week
  if(!isMobile) {
    $('input[type="date"]').each(function() {
      $(this).attr("type", "text");
    });
    $('input[type="time"]').each(function() {
      $(this).attr("type", "text");
    });
    $("#salida").timepicker();
    $("#lala").datepicker();
  }
});
deblocker
  • 7,277
  • 2
  • 18
  • 49