Materialize: Datepicker - pick -> close

Created on 8 Mar 2015  路  15Comments  路  Source: Dogfalo/materialize

Hi,

it would be great if we had possibility (an option) to close datepicker when date was selected. It's shortcut to "select date" -> "click Close".

Thanks.

Most helpful comment

Workaround:

$('.datepicker').pickadate({
    onSet: function( arg ){
        if ( 'select' in arg ){ //prevent closing on selecting month/year
            this.close();
        }
    }
});

All 15 comments

It seems latest datepicker already does this by default, and provides an option to leave the picker open after selecting the date: http://amsul.ca/pickadate.js/date/#close-on-action

This is how it was originally, but its behavior was changed to match Google's date picker.

@ciencia You are right, thank for the hint

@Dogfalo Thanks, I get that. Anyway if there would be the option, like in original pickadate.js is, it would be great. Frankly, when you choose a date, you don't need the calendar anymore -> close it.
P.S. I'm using latest 0.96.1 version

@Dogfalo I also prefer the original behavior as well. What do you think about having the option to enable it with

$('.datepicker').pickadate({
  closeOnSelect: true
})

@Dogfalo I would also like the option to have it close once the date is selected.

Yeah @Dogfalo closeOnSelect: true would be great... does anyone have a work arround for this?

Workaround:

$('.datepicker').pickadate({
    onSet: function( arg ){
        if ( 'select' in arg ){ //prevent closing on selecting month/year
            this.close();
        }
    }
});

@ivanklun thanks for the workaround.
This should be mention in the docs if the closeOnSelect is not chosen. It's hard to find this in the closed issues.

thanks for the workaround, works fine

Could you reconsider opening this? I don't think having the option to autoclose the picker would harm anyone

You should try the workaround @ivanklun suggested.

I'm grateful for @ivanklun solution but that's still a hacky workaround - why is this issue closed without a proper solution?

After much research this has worked for me!!! version materialize 0.98.2

jQuery(document).ready(function(){
   $('#optDate').pickadate({format: 'yyyy-mm-dd'})
                      .on('change', function(){
                              `$(this).next().find('.picker__close').click();`
                      });
});

@robertoradical great workaround, works for me thanks!
To implement the close on select functionality on all the datepickers just use this code based on @robertoradical solution.

    $('.datepicker').on('change', function(){
        $(this).next().find('.picker__close').click();
    });

plz make the option to closeOnSelect work :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Robouste picture Robouste  路  3Comments

ReiiYuki picture ReiiYuki  路  3Comments

ericlormul picture ericlormul  路  3Comments

onigetoc picture onigetoc  路  3Comments

heshamelmasry77 picture heshamelmasry77  路  3Comments