Question

I'm using Twitter bootstrap "TimePicker" widget. This widget has behavior of increasing/decreasing time when ".keydown" event is fired.

I need to block this default behavior. How I could achieve that?

Currently I try to intercept and block events on html input element directly. I see that .keydown events are intercepted and prevented, but TimePicker .keydown event still fires:

    $('#timeInput').keydown(function (e) {
        var keyCode = e.keyCode || e.which,
            arrow = { up: 38, down: 40 };

        switch (keyCode) {
            case arrow.up:
                window.debug.info("Key Up prevented");
                event.preventDefault();
                break;
            case arrow.down:
                window.debug.info("Key Down prevented");
                event.preventDefault();
                break;
        }
    });

Can I override "TimePicker" control default behavior?

Was it helpful?

Solution

You can remove keydown behavior anytime doing:

$('#timeInput').unbind('keydown');

or right after the widget initialization:

$('#timeInput').timepicker(options).unbind('keydown');

OTHER TIPS

As you're sending the event named e, just change this:

event.preventDefault();

to that:

e.preventDefault();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top