2.0.0 • Published 7 years ago

vuejs-range-datepickers v2.0.0

Weekly downloads
137
License
MIT
Repository
github
Last release
7 years ago

vuejs-range-datepickers

Component utilizing VueJS-Datepicker for a Data Range Select for VueJs.

Installation


###npm

npm install --save vuejs-range-datepickers

Usage


//   app.js
window.Vue = require('vue');

Vue.component('range-datepickers',require('vuejs-range-datepickers'));

const app = new Vue({
  el: '#app'
})

value prop if passed should be a Date object or valid date string

//   index.html
<!doctype html>
  <html>
    <head>
      <meta charset="utf-8"/>
    </head>
    <body>
      <div id="app">
        <range-datepickers start-date="06-10-2017" end-date="06-20-2017"></range-datepickers>
      </div>
      <script src="main.js"></script>
    </body>
  </html>

more uses cases

<script>
var state = {
    date: new Date(2016, 9,  16)
}
</script>
<range-datepickers :value="state.date"></range-datepickers>

support name attribute for normal html form submission

<range-datepickers :value="state.date" name="uniquename"></range-datepickers>

Use v-model for two-way binding

<range-datepickers v-model="state.date" name="uniquename"></range-datepickers>

Inline always open version

<range-datepickers :inline="true"></range-datepickers>

Available props

PropTypeDefaultDescription
valueDate/StringDate value of the datepicker
nameStringInput name property
idStringInput id
formatStringdd MMM yyyyDate formatting string
languageStringenTranslation for days and months
disabledObjectSee below for configuration
placeholderStringInput placeholder text
inlineBooleanTo show the datepicker always open
input-classStringCSS class applied to the input el
wrapper-classStringCSS class applied to the outer div
monday-firstBooleanfalseTo start the week on Monday
clear-buttonBooleanfalseShow an icon for clearing the date
clear-button-iconStringUse icon for button (ex: fa fa-times)
calendar-buttonBooleanfalseShow an icon that that can be clicked
calendar-button-iconStringUse icon for button (ex: fa fa-calendar)
bootstrapStylingBooleanfalseOutput bootstrap styling classes
initial-viewString'day'If 'month' or 'year', open on that view
disabled-pickerBooleanfalseIf true, disable Datepicker on screen
requiredBooleanfalseSets html required attribute on input
bootstrap-rowBooleantrueSets html styles for .row with even cols
restrict-datesBooleantrueRestrict the end date to be past start
start-labelString"FROM:"Adjust/remove a label for the start input
end-labelString"TO:"Adjust/remove a label for the end input
submit-callbackFunctionnullSet a callback to handle button event
submit-textString"UpDate"Sets submit button text
disabled-datesArray[]Array of Datesdate strings
no-overlapBooleantrueForces End Date to change if overlapping after start date changed
minimum-durationNumber1Sets end date to start + minimum-duration if overlap occurs

Available data attributes

This data is used to restrict both calendars for a date range and specific dates that may change use the recommended disabled-dates property if your data will not change

defaultDisabledDates: {
    to: new Date('1990-12-31'),
    from: new Date('3333-12-31'),
    dates: []
},

slots

  • header-title
  • header-legend
  • button

Date formatting

NB. This is not very robust at all - use at your own risk! Needs a better implementation.

TokenDescExample
dday1
dd0 prefixed day01
Dabbr dayMon
sudate suffixst, nd, rd
Mmonth number (1 based)1 (for Jan)
MM0 prefixed month01
MMMabbreviated month nameJan
MMMMmonth nameJanuary
yytwo digit year16
yyyyfour digit year2016

Translations

<datepicker language="es"></datepicker>

Available languages

AbbrLanguage
enEnglishDefault
bsBosnian
esSpanish
fiFinnish
frFrench
huHungarian
hrCroatian
idIndonesian
itItalian
nlDutch
deGerman
daDanish
nb-noNorwegian Bokmål
csCzech
pt-brPortuguese-Brazil
roRomanian
viVietnamese
zhChinese
jaJapanese
heHebrew
ruRussian
skSlovak
sl-siSlovenian
svSwedish
thThai
bgBulgarian
ltLithuanian
plPolish
arArabic
eeEstonian
koKorean
trTurkish
ukUkrainian
isIcelandic

Live Example


I have created an example vue webapp (documentation here), demonstrating this range date selector via simple vue app.

TODOs


  • allow minimum-duration to be and array of dates with a duration
  • get more feedback!

Contributions


All contributions are welcome: use-cases, documentation, code, patches, bug reports, feature requests, etc. You do not need to be a programmer to speak up!

version changes

v1.0.0

  • start date is no longer restricted by end date.
  • can disable an array of dates :disable-dates
  • defaults to not allow overlapping disabled dates :no-overlap
  • defaults to :end-plus="1" which adds this value to end date if the overlapping forces the end-date to change
  • :default-disabled-dates is the datepicker 'disabled' option for both of the range pickers. this allows for setting max (from), min (to), and dates (disabled individual dates) that can be modified by parent components

v1.2.0

  • removed end-plus , changed to minimum-duration
  • other date restrictions based on minimum-duration and disabled-dates...
2.0.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago