简体   繁体   English

jQuery UI日期选择器未在移动iOS和Android上显示(但在桌面上显示)

[英]jQuery UI date picker doesn’t show up on mobile iOS and Android (but shows on desktop)

I use a jQuery UI date picker on a web site. 我在网站上使用jQuery UI日期选择器。

It works very well on desktop browsers, the calendar is showing up when user click on input and i can save the selected date. 它在桌面浏览器上非常有效,当用户单击输入时日历会显示出来,我可以保存所选的日期。

My issue is on mobile devices (iOS and Android), the calendar is not showing and i have the native iOS date sector which have the wrong format : 我的问题是在移动设备(iOS和Android)上,日历未显示,并且我具有格式错误的本地iOS日期扇区:

On mobile, i don't see the date picker : 在移动设备上,我看不到日期选择器:

在此处输入图片说明

On desktop, it works fine : 在桌面上,它可以正常工作:

在此处输入图片说明

Here is the html code of the input (custom module on Drupal 8 so the html is generated by the Form API) : 这是输入的html代码(Drupal 8上的自定义模块,因此html由Form API生成):

<input type="date" data-drupal-selector="edit-date-debut" aria-describedby="edit-date-debut--description" data-drupal-date-format="Y-m-d" class="form-date required form-control hasDatepicker" id="edit-date-debut" name="date_debut" value="" required="required" aria-required="true" step="300">

I've tried to force the date format with JS (it works on desktop) but i still have the iOS date selector : 我试图用JS强制日期格式(它在桌面上可用),但是我仍然有iOS日期选择器:

$("#edit-date-debut").datepicker({ dateFormat: 'dd-mm-yy' });

I've tried to turn the input in text-input and then attach datepicker. 我试图将输入转换为文本输入,然后附加日期选择器。 Still no luck. 仍然没有运气。

$("#edit-date-debut").attr('type','text');
$("#edit-date-debut").datepicker({ dateFormat: 'dd-mm-yy' });

For now, what i can do is generated an input type texte : 现在,我能做的就是生成输入类型texte:

<input data-drupal-selector="edit-date-debut" aria-describedby="edit-date-debut--description" class="form-text required form-control hasDatepicker" type="text" id="edit-date-debut" name="date_debut" value="" size="60" maxlength="128" required="required" aria-required="true" readonly="readonly">

Then, i attach the datepicker and it still working on desktop. 然后,我附加了日期选择器,它仍然可以在桌面上运行。 On mobile, i don't see anymore the native date selector with the wrong format. 在移动设备上,我不再看到格式错误的本地日期选择器。 I still have no date picker calendar but user can type the date in input text. 我仍然没有日期选择器日历,但用户可以在输入文本中键入日期。 So it's a first step. 所以这是第一步。

Do you know how can i handle this ? 你知道我该怎么处理吗?

The solution is not to use : 解决方法是不使用:

<input type="date">

but

<input type="text">

And attach a date picker like jQuery Datepicker or Bootstrap Datepicker 并附加一个日期选择器,例如jQuery DatepickerBootstrap Datepicker

In safari, i need to test in private mode because sometines the Safari cache prevents me to see update in my JS. 在Safari中,我需要在私有模式下进行测试,因为Safari缓存中的某些例程阻止我查看JS中的更新。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM