Skip to content

Instantly share code, notes, and snippets.

@JesseRWeigel
Created February 17, 2017 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JesseRWeigel/04e37cd5eb6f98f37c98870715be5721 to your computer and use it in GitHub Desktop.
Save JesseRWeigel/04e37cd5eb6f98f37c98870715be5721 to your computer and use it in GitHub Desktop.
Materialize Datepicker Set Year Function
(function () {
let thisInputID, thisPickerID;
$('.datepicker').pickadate({
//Other options can go here
onOpen: function() {
//Get ID for input and this particular picker
thisInputID = `#${$(this.$node.context).attr('id')}`;
thisPickerID = `${thisInputID}_root`;
},
onClose: function() {
//Get date from selected day element and save as a variable
let date = ($(`${thisPickerID} .picker__day--highlighted`).attr('aria-label'));
//Insert date into input
$(thisInputID).val(date);
},
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment