indrimuska / angular-moment-picker

Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js.
http://indrimuska.github.io/angular-moment-picker/
MIT License
525 stars 226 forks source link

jQuery compatibility #158

Closed easyest closed 7 years ago

easyest commented 7 years ago

If jQuery is loaded, then it is not possible to enter date by keyboard into an input. Plunker here: https://plnkr.co/edit/hs10SM?p=preview

It would seem the problem is with the code: .on('keydown', function (e) { return $scope.keyboard && $scope.$evalAsync(function () { return $scope.view.keydown(e); }); });

jQuery documentation mentions that:

Returning false from an event handler will automatically call event.stopPropagation() and event.preventDefault(). A false value can also be passed for the handler as a shorthand for function(){ return false; }. So, $( "a.disabled" ).on( "click", false ); attaches an event handler to all links with class "disabled" that prevents them from being followed when they are clicked and also stops the event from bubbling.

easyest commented 7 years ago

I fixed the problem by changing the code from:

.on('keydown', function (e) { return $scope.keyboard && $scope.$evalAsync(function () { return $scope.view.keydown(e); }); });

to:

.on('keydown', function (e) {
    if ($scope.keyboard) {
        return $scope.$evalAsync(function() { return $scope.view.keydown(e); });
    } else {
        return true;
    }
});
indrimuska commented 7 years ago

Thank you @easyest, this fix will be available in the next release!

easyest commented 7 years ago

Many thanks :)

cvuorinen commented 7 years ago

I ran into this same issue and was just about to make a pull request and noticed it was already fixed in master.

Any info when next release might be tagged?

indrimuska commented 7 years ago

Hi @cvuorinen, I'll release next version next Tuesday.