krescruz / angular-materialize

Angularjs directives for Materialize CSS Framework https://github.com/Dogfalo/materialize
MIT License
396 stars 129 forks source link

no option to close input-date on select #196

Open jacek213 opened 8 years ago

jacek213 commented 8 years ago

As stated in the title. I'm aware that it's the default behaviour of pickadate provided by materialize and I know it can be hacked by closing it in onSet function with jquery, but it would be nice if it was configurable option, especially considering the fact that that's the way the "clean" pickadate works by default.

jacek213 commented 7 years ago

If anyone is facing the same issue, here is my workaround (based on solution for core materialize lib - https://github.com/Dogfalo/materialize/issues/870#issuecomment-168944579):

(function() {
  'use strict';

  angular
    .module('myappmodule')
    .directive('inputDate', inputDate);

  // this decorator enables new option: closeOnSelect -> false by default

  /** @ngInject */
  function inputDate() {
    var directive = {
      link: link
    };

    return directive;

    function link(scope, elem, attrs) {
      if (attrs.closeOnSelect) {
        elem.pickadate({
          onSet: function(arg){
            if ('select' in arg){ //prevent closing on selecting month/year
              this.close();
            }
          }
        });
      }
    }
  }

})();
ghost commented 7 years ago

Please see this PR: Dogfalo/materialize#4003 that shows how to fix without the hacky workaround.

webbiesdk commented 7 years ago

I think we'll wait and see if Dogfalo/materialize#4003 gets merged, and if it does, then that makes our implementation much easier.

Until then, others can use the workaround.