Skip to content

Instantly share code, notes, and snippets.

@ohnotnow
Last active February 19, 2018 10:27
Show Gist options
  • Save ohnotnow/bdd8f4e6f4eed6ec9b1d12c207b31d74 to your computer and use it in GitHub Desktop.
Save ohnotnow/bdd8f4e6f4eed6ec9b1d12c207b31d74 to your computer and use it in GitHub Desktop.
Vuejs directive for pikaday
// npm install pikaday
// resources/assets/js/app.js
import Pikaday from "pikaday";
import "pikaday/css/pikaday.css";
Vue.directive("pikaday", {
bind: (el, binding) => {
el.pikadayInstance = new Pikaday({
field: el,
onSelect: () => {
var event = new Event("input", { bubbles: true });
el.value = el.pikadayInstance.toString();
el.dispatchEvent(event);
}
});
},
unbind: el => {
el.pikadayInstance.destroy();
}
});
// then in a template
<input class="input" type="text" v-model="whatever" placeholder="YYYY-MM-DD" v-pikaday>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment