Search code examples
jquerydatetimepickerbootstrap-datetimepickereonasdan-datetimepicker

Bootstrap Datetimepicker - blur() when pressing enter


While editing directly the date inside the input-field of my datetimepicker (without opening the widget), I want by keypressing enter to confirm the entered date.

I think that just calling blur() should that do.

But I don't know how to run blur()on the input-field of my datetimepicker. Has anybody an idea?

$(".mydatepicker").datetimepicker({
    locale: "de",
    format: "L",
    minDate: "1900/01/01",
    keyBinds: {
        enter: function () {
            // "this.input.blur();"
        }
    }
})

Not the cleanest, but working Solution:

$(".mydatepicker").datetimepicker({
    locale: "de",
    format: "L",
    minDate: "1900/01/01",
    keyBinds: {
        enter: function () {
            this.show();
            this.hide();
        }
    }
})

Solution

  • Added as answer because OP liked the solution.

    Rather than using blur() another option is to use dp.hide() and dp.show() when the picker needs to be open or closed. With this there is more control and it may be easier since focus and blur programming can be a bit annoying

    Check the docs for more information