Clockpicker: How to prevent click on input to open clockpicker

只愿长相守 提交于 2019-12-11 00:22:46

问题


I'm using weareoutman's clockpicker on my page. How to prevent click on input to show clockpicker or fade in overlay before clockpicker come to visible? I just wanted to fade in overlay before clockpicker shows. Click on "button" is working as desired. So far I have tried beforeShow function in clockpicker also e.preventDefault() and e.stopPropagation() -functions in jQuery.

HTML:

<div class="dialog">
    <div>Clock:</div>
    <div class="input-group" id="clockpicker">
        <input type="text" id="start-time" class="clock text-right" readonly />
        <span class="button button-gray icon icon-clock"></span>
    </div>
<div class="dialog-overlay hide"></div>
</div>

jQuery:

var clock = jQuery('#clockpicker'),
    dialog_overlay = jQuery('.dialog-overlay');

clock.clockpicker({
    autoclose: true,
    afterDone: function() {
        dialog_overlay.fadeOut('slow');
    }
});

clock.on('click', function(e) {
    dialog_overlay.fadeIn('slow', function() {
        clock.clockpicker('show');
    });
});

回答1:


I have found a solution to the problem. Set click event off in input field.

clock.find('input').off('focus.clockpicker click.clockpicker');

I hope that this solution helps someone else also.




回答2:


With recent versions of library you can do something like this:

$('#inputId').clockpicker({
        beforeShow: function e() {            
            var condition = "...";
            if (!condition) {
                e.stopPropagation();
            }
        }            
    });


来源:https://stackoverflow.com/questions/34978129/clockpicker-how-to-prevent-click-on-input-to-open-clockpicker

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