Skip to content

Instantly share code, notes, and snippets.

@willishq
Created February 13, 2017 23:10
Show Gist options
  • Save willishq/0a577a7f2f42ba8e97636f86cbb4a502 to your computer and use it in GitHub Desktop.
Save willishq/0a577a7f2f42ba8e97636f86cbb4a502 to your computer and use it in GitHub Desktop.
Bootstrap Vue Datepicker
<template>
<div class="form-group">
<label :for="name">Date of Birth</label>
<div class="form-inline">
<input type="number" :id="name" min="1" step="1" :max="maxDay" size="2" class="form-control" v-model="day" placeholder="Day">
<select class="form-control" v-model="month">
<option value="-1" disabled>Month</option>
<option v-for="(month, index) in months" :value="index">{{ month }}</option>
</select>
<input type="number" :min="minYear" :max="maxYear" class="form-control" v-model="year">
</div>
<input type="hidden" :name="name" :value="dateString">
</div>
</template>
<script>
import _ from 'lodash';
import moment from 'moment';
export default {
props: ['name', 'required', 'minYear', 'maxYear'],
data() {
return {
year: null,
month: 0,
day: null,
months: _.times(12).map(i => moment().month(i).format('MMMM'))
};
},
computed: {
maxDay() {
return moment([this.year || moment().year(), this.month]).daysInMonth() || 31;
},
dateString() {
return moment([this.year, this.month, this.day]).format('YYYY-MM-DD');
}
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment