talkhabi / vue-persian-datetime-picker

A vue plugin to select jalali date and time
https://talkhabi.github.io/vue-persian-datetime-picker/
588 stars 78 forks source link
datepicker jalali persian vue-components vuejs

vue-persian-datetime-picker

npm version

A vue plugin to select jalali date and time

See documentation and demo at vue-persian-datetime-picker

If you are using vuejs 3, please refer to this repository.

Installation

browser

<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://cdn.jsdelivr.net/npm/moment"></script>
<script src="https://cdn.jsdelivr.net/npm/moment-jalaali@0.9.2/build/moment-jalaali.js"></script>
<script src="https://github.com/talkhabi/vue-persian-datetime-picker/raw/master/dist/vue-persian-datetime-picker.umd.min.js"></script>
<div id="app">
  <date-picker v-model="date"></date-picker>
</div>
<script>
var app = new Vue({
  el: '#app',
  data: {
    date: '1397/02/02'
  },
  components: {
    DatePicker: VuePersianDatetimePicker
  }
});
</script>

npm

npm install vue-persian-datetime-picker --save

Configuration for moment to ignore loading locales

// webpack.config.js:
module.exports.plugins = [
  //...
  new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
  //...
]

// vue.config.js:
module.exports = {
  //..
  configureWebpack: {
    plugins: [new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)]
  },
  //...
}

Usage

// main.js
//...
import VuePersianDatetimePicker from 'vue-persian-datetime-picker';
Vue.component('date-picker', VuePersianDatetimePicker);
//...

Or in component

<template>
  <div>
    <date-picker v-model="date"></date-picker>
  </div>
</template>

<script>
import VuePersianDatetimePicker from 'vue-persian-datetime-picker'
export default {
  data(){
    return {
      date: ''
    }
  },
  components: {
    datePicker: VuePersianDatetimePicker
  }
}
</script>

You can also set default values:

// main.js
import VuePersianDatetimePicker from 'vue-persian-datetime-picker';
Vue.use(VuePersianDatetimePicker, {
  name: 'custom-date-picker',
  props: {
    inputFormat: 'YYYY-MM-DD HH:mm',
    format: 'jYYYY-jMM-jDD HH:mm',
    editable: false,
    inputClass: 'form-control my-custom-class-name',
    placeholder: 'Please select a date',
    altFormat: 'YYYY-MM-DD HH:mm',
    color: '#00acc1',
    autoSubmit: false,
    //...  
    //... And whatever you want to set as default 
    //... 
  }
});

Then use in component

<custom-date-picker v-model="date" />

Click to see full documentation and demo

Built With

License

This project is licensed under the MIT License

Change log

2.10.4 (2022-03-04)

2.10.3 (2022-01-06)

2.10.2 (2021-12-24)

2.10.1 (2021-11-12)

2.10.0 (2021-11-03)

2.9.1 (2021-10-31)

2.9.0 (2021-09-27)

2.8.0 (2021-08-01)

2.7.0 (2021-07-23)

2.6.1 (2021-05-17)

2.6.0 (2021-02-05)

2.5.0 (2021-01-30)

2.4.1 (2020-11-13)

2.4.0 (2020-10-17)

2.3.0 (2020-08-30)

2.2.0 (2020-08-02)

2.1.6 (2020-07-13)

2.1.5 (2020-04-19)

2.1.4 (2020-01-30)

2.1.2 (2019-09-08)

2.1.1 (2019-09-07)

2.1.0 (2019-08-19)

2.0.2 (2019-07-17)

2.0.1 (2019-05-11)

2.0.0 (2019-01-16)

1.1.7 (2018-12-31)

1.1.6 (2018-12-29)

1.1.5 (2018-09-01)

1.1.4 (2018-08-12)

1.1.3 (2018-05-22)

1.1.2 (2018-05-12)

1.1.1 (2018-05-03)

1.1.0 (2018-05-01)

1.0.9 (2017-12-25)

1.0.7 (2017-12-14)

1.0.5 (2017-12-04)