简体   繁体   English

如何停止关闭日期选择器模糊?

[英]How to stop the closing of date-picker on blur?

Problem问题

I am using pickadate.js and I want my date-picker calendar to remain open on clicking outside the calendar.我正在使用pickadate.js并且我希望我的日期选择器日历在日历外单击时保持打开状态。 Thanks in Advance.提前致谢。

What I have tried我试过的

Firstly, I have tried picker.set('select', new Date());首先,我尝试过picker.set('select', new Date()); , but it also closes the date picker because, if the date is selected, then it is not closing the date picker on clicking the header of the modal, but if we are not initializing the date picker then it closes the date picker on clicking the modal's header. ,但它也会关闭日期选择器,因为如果选择了日期,那么它不会在单击模态标题时关闭日期选择器,但是如果我们没有初始化日期选择器,那么它会在单击时关闭日期选择器模态的标题。

Each time a picker is opened, an event handler to close it is bound to the document with a particular namespace ( $document.on( 'click.' + STATE.id) in the code).每次打开选择器时,都会将关闭它的事件处理程序绑定到具有特定命名空间的$document.on( 'click.' + STATE.id)代码中$document.on( 'click.' + STATE.id) )。 Then the code triggers the 'open' events.然后代码触发“打开”事件。
By binding an event handler on this 'open' event, we can immediately unbind the document event that closes the picker (with the specific id).通过在这个 'open' 事件上绑定一个事件处理程序,我们可以立即解除关闭选择器的文档事件(具有特定的 id)。

 var input = $('.datepicker').pickadate(), picker = input.pickadate('picker'); picker.on('open', function() { $(document).off('.' + picker.get('id')) });
 .picker__holder { width: 350px !important; }
 <link href="https://amsul.ca/pickadate.js/vendor/pickadate/lib/themes/default.css" rel="stylesheet" /> <link href="https://amsul.ca/pickadate.js/vendor/pickadate/lib/themes/default.date.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://amsul.ca/pickadate.js/vendor/pickadate/lib/picker.js"></script> <script src="https://amsul.ca/pickadate.js/vendor/pickadate/lib/picker.date.js"></script> <input id="input_01" class="datepicker" name="date" type="text" autofocus value="14 August, 2014" data-value="2014-08-08">

Example with materialize 1.0.0实例化 1.0.0

 //added autoClose:true to close the modal when a date is picked var input = $('.datepicker').datepicker({autoClose: true}); //and changed the dismissible property of the datepicker modal input[0].M_Datepicker.modal.options.dismissible = false;
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" rel="stylesheet" /> <input id="input_01" class="datepicker" name="date" type="text" autofocus value="14 August, 2014" data-value="2014-08-08">

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

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