• This repository has been archived on 13/Nov/2018
  • Stars
    star
    224
  • Rank 177,792 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vue.js component for eonasdan bootstrap datetimepicker

Vue Bootstrap 4 DatetimePicker

vue-js downloads npm-version github-tag license build-status codecov

Vue.js component for eonasdan-bootstrap-datetimepicker

Demo on JSFiddle

Versions

👉 If you are looking for the documentation of an older version then switch to respective version branch.

Package Version Bootstrap CSS version Underlying Library API Docs (same for both)
4.x 3.x eonasdan-bootstrap-datetimepicker (Official) Docs
5.x 4.x pc-bootstrap4-datetimepicker (Fork) Docs

Features

  • Reactive v-model value
    • You can change datepicker value programmatically
  • Reactive config options
    • You can change config options dynamically
    • Component will watch for changes and apply them
    • You are suggested to modify config via Vue.set
  • Emits all possible events
  • Works with vee-validate and other validation library

Requirements

  • Bootstrap ^4 (only css)
  • jQuery >=1.8.3
  • Moment.js ^2.22

Installation

# npm
npm install vue-bootstrap-datetimepicker --save

# Yarn
yarn add vue-bootstrap-datetimepicker

Using Webpack?

// webpack.config.js
plugins: [
    new webpack.ProvidePlugin({
      Vue: ['vue/dist/vue.esm.js', 'default'],
      jQuery: 'jquery',
      'window.jQuery': 'jquery',
      $: 'jquery',
      moment: 'moment',
    }),
  ]  

Using Laravel Mix?

  • Update your webpack.mix.js file, ref
// webpack.mix.js
mix.autoload({
    'jquery': ['$', 'window.jQuery', 'jQuery'],
    'vue': ['Vue','window.Vue'],   
    'moment': ['moment','window.moment'],   
  })

Icon Fonts missing?

  • Bootstrap v4 does not come with any icon fonts. You can import font-awesome v5 icons css.
// app.js
jQuery.extend(true, jQuery.fn.datetimepicker.defaults, {
    icons: {
      time: 'far fa-clock',
      date: 'far fa-calendar',
      up: 'fas fa-arrow-up',
      down: 'fas fa-arrow-down',
      previous: 'fas fa-chevron-left',
      next: 'fas fa-chevron-right',
      today: 'fas fa-calendar-check',
      clear: 'far fa-trash-alt',
      close: 'far fa-times-circle'
    }
});

Usage Example

<template>
  <div class="container">
    <div class="row">
      <div class="col-md-12">
        <date-picker v-model="date" :config="options"></date-picker>
      </div>
    </div>
  </div>
</template>

<script>
  // Import required dependencies 
  import 'bootstrap/dist/css/bootstrap.css';
  
  // Import this component
  import datePicker from 'vue-bootstrap-datetimepicker';
  
  // Import date picker css
  import 'pc-bootstrap4-datetimepicker/build/css/bootstrap-datetimepicker.css';
   
  export default {    
    data () {
      return {
        date: new Date(),
        options: {
          format: 'DD/MM/YYYY',
          useCurrent: false,
        }       
      }
    },
    components: {
      datePicker
    }
  }
</script>

As plugin

  import Vue from 'vue';
  import datePicker from 'vue-bootstrap-datetimepicker';
  import 'bootstrap/dist/css/bootstrap.css';
  import 'pc-bootstrap4-datetimepicker/build/css/bootstrap-datetimepicker.css';
  Vue.use(datePicker);

This will register a global component <date-picker>

Events

  • The component emits all available events
  • You can listen to them in your component like -
<date-picker v-model="date" @dp-hide="doSomethingOnHide" @dp-change="doSomethingOnChange"></date-picker>

Available props

The component accepts these props:

Attribute Type Default Description
v-model / value String / Date Object / moment / null null Set or Get date-picker value
config Object {} Datetime picker configuration options
wrap Boolean false Set this to true when wrapped in 'input-group'

Install in non-module environments (without webpack)

<!-- Date-picker dependencies -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" rel="stylesheet">

<!-- Date-picker itself -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/js/bootstrap-datetimepicker.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/build/css/bootstrap-datetimepicker.min.css" rel="stylesheet">

<!-- Vue js -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<!-- Lastly add this package -->
<script src="https://cdn.jsdelivr.net/npm/vue-bootstrap-datetimepicker@5"></script>
<script>
  // Initialize as global component
  Vue.component('date-picker', VueBootstrapDatetimePicker);
</script>

Run examples on your localhost

  • Clone this repo
  • You should have node-js >=6.10 and yarn >=1.x pre-installed
  • Install dependencies - yarn install
  • Run webpack dev server - yarn start
  • This should open the demo page at http://localhost:9000 in your default web browser

Testing

  • This package is using Jest and vue-test-utils for testing.
  • Tests can be found in __test__ folder.
  • Execute tests with this command - yarn test

Changelog

Please see CHANGELOG for more information what has changed recently.

Caveats

  • ⚠️ Don't pass config option as inline literal object to :config prop.
<!-- This will cause date picker to freeze -->
<date-picker v-model="card" :config="{format: 'DD/MM/YYYY'}"></date-picker>
  • Vue.js can not detect changes when literal object/arrays passed within template, see

License

MIT License

More Repositories

1

vue-loading-overlay

Vue.js component for full screen loading indicator 🌀
JavaScript
1,219
star
2

vue-flatpickr-component

Vue.js component for Flatpickr datetime picker 📆
TypeScript
964
star
3

vue-toast-notification

Yet another toast notification plugin for Vue.js 🌷
JavaScript
615
star
4

vue-cleave-component

Vue.js component for Cleave.js input mask library ⌨️
JavaScript
281
star
5

vue-trumbowyg

Vue.js component for Trumbowyg WYSIWYG editor 📝
JavaScript
236
star
6

google-chat-electron

An unofficial desktop app for Google Chat :electron:
TypeScript
158
star
7

vue-web-storage

Vue.js plugin for local storage and session storage (1.8 kb min+gz) 💾
TypeScript
85
star
8

fcm-notification-channel

All in One Firebase push notification channel for Laravel 🔔
PHP
68
star
9

laravel-eloquent-relationships

Add some more eloquent relationships to Laravel php framework. 👫
PHP
57
star
10

phpunit-travis-ci-coverage-example

phpUnit Testing on Travis-CI with Code Coverage on CodeCov
PHP
28
star
11

laravel-mix-auto-extract

[DEPRECATED] Laravel Mix v2/3 plugin to auto extract vendor js
JavaScript
25
star
12

laravel-ses-webhooks

AWS SES Webhooks client for Laravel 📬
PHP
22
star
13

laravel-socialite-multiple-providers-example

Laravel socialite with multiple providers example
PHP
20
star
14

vue-jquery-mask

Vue.js component for jQuery mask plugin
JavaScript
20
star
15

vue-lunch-order-app

Lunch order app, built with Vue.js v2 and Google Spreadsheet
JavaScript
17
star
16

laravel-paypal-webhooks

Handle PayPal webhooks in Laravel 💵
PHP
16
star
17

bandwidth-notification-channel

Bandwidth SMS notification channel for Laravel php framework 📩
PHP
12
star
18

wp-google-map

Google Map Plugin for WordPress
PHP
11
star
19

laravel-bundler

Modern asset building tool for Laravel framework with better defaults. 📦
JavaScript
11
star
20

codeception-travis-ci-example

[READ-ONLY] Codeception Acceptance Testing on Travis-CI
PHP
9
star
21

wp-prism-js

Prism Syntax Highlighter Plugin for WordPress
PHP
7
star
22

vue-bugsnag

[DEPRECATED] Vue.js plugin for Bugsnag js v3.x error reporting
JavaScript
6
star
23

vue-progress-indicator

Vue.js component for progress indicator
JavaScript
5
star
24

electron-update-notifier

Update notifier for Electron apps 🔔
TypeScript
5
star
25

laravel-form-validation

Yet another form validation (JS) helper for Laravel. ☂️
TypeScript
5
star
26

laravel-blogger-api-example

Laravel demo blog REST api 🧙‍♂️
PHP
4
star
27

laravel-stripe-exceptions

Handle Stripe exceptions gracefully in Laravel php framework. ☄️
PHP
4
star
28

node-webkit-angular-starter-kit

[READ-ONLY] A node-webkit and Angular js based desktop app
JavaScript
3
star
29

laravel-alert

A Bootstrap alert helper for Laravel php framework 🥭
PHP
3
star
30

laravel-lunch-order-app

[WIP] Lunch order app built with Laravel
PHP
2
star
31

laravel-vonage-inbound-sms

Vonage Inbound SMS Webhooks Client for Laravel ☎️
PHP
2
star
32

wp-google-analytics

Google Analytics Plugin for WordPress
PHP
2
star
33

gulp-3-browsersync-scss-seed

[READ-ONLY] Front-end development starter kit for beginners
JavaScript
2
star
34

vue-php-demo-2021

Sample app to demo vue.js with php
PHP
2
star
35

laravel-otp

One time password (OTP) generator and verifier for Laravel 📲
PHP
2
star
36

ankurk91.github.io

Ankur Kumar's GitHub Profile 🎉
HTML
1
star
37

ankurk91

The README repo 😉
1
star
38

laravel-passport-socialite-example

Laravel passport with socialite
PHP
1
star
39

laravel-shopping-cart

Shopping cart manager for Laravel. 🛒
PHP
1
star
40

wp-tabs-example

WordPress plugin to demonstrate how to use in-built tabs on plugin options page
PHP
1
star
41

wp-lazy-intercom

WordPress plugin to lazy load Intercom widget
PHP
1
star
42

wp-screen-options-example

WordPress plugin to demonstrate screen options usage in your plugin options page
PHP
1
star